Pages

Monday, April 21, 2014

SQL Server: How to truncate a date

Many times we have been encountered with the necessity to  truncate a date to retrieve data from defined periods of time.

With SQL Server 2008 and above, this is simple done executing the query below:

SELECT cast(getDate() AS Date)

For previous versions, the proper way to do it is:

SELECT dateAdd(dd, dateDiff(dd,0, getDate()), 0)

0 comments:

Post a Comment