Posted By

dotNetkow on 12/07/10


Tagged

sql year date


Versions (?)

Year To Date


 / Published in: SQL
 

Generates a year-to-date string (ex: 2010-01-01) by appending the year to the first of the year.

  1. SELECT (CONVERT(VARCHAR(4), GETDATE(), 111) + '-01-01') AS [Year TO Date]
  2.  
  3.  
  4. -- Usage (date range):
  5. SELECT *
  6. FROM TABLE
  7. WHERE my_date BETWEEN (CONVERT(VARCHAR(4), GETDATE(), 111) + '-01-01') AND GETDATE()

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: dotNetkow on January 19, 2011

A better version: DATEADD(yy, DATEDIFF(yy,0,getdate()), 0);

You need to login to post a comment.