Posted By

Scooter on 02/15/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Tyster


Get the current date without the time in SQL Server


 / Published in: SQL
 

Quite often I need to select all records in a table where the date is equal to today. The GETDATE() function in Transact-SQL returns the date and the time. The time vlaue can be stripped off by subtracting each part (hour, minute, second, millisecond).

  1. DATEADD(hh, -DATEPART(hh, GETDATE()), DATEADD(mi, -DATEPART(mi, GETDATE()), DATEADD(s, -DATEPART(s, GETDATE()), DATEADD(ms, -DATEPART(ms, GETDATE()), GETDATE()))))

Report this snippet  

You need to login to post a comment.