SQLTeam.com | Weblogs | Forums

CASE Statement with Date

Greetings,

I am trying to retrieve a Start Date with the following CASE statement:

, CASE WHEN a.STARTDATE < (SELECT DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)) THEN (SELECT DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0))

If the date is less than the first date of the current year, then I want it to return that first day of the current year, However it is returning it as a DATETIME, and I would like it to return it as a DATE in the format of YYYY-MM-DD.

Thank you.

CAST the result as a date:

CASE WHEN a.STARTDATE < (SELECT DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)) THEN CAST((SELECT DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)) AS date)

Thanks Scott! It works perfectly.