You are currently browsing the category archive for the ‘SQL’ category.

Quite often during data conversion processes, I am required to get only the date part from a datetime or a timestamp value. Here is a trick that does not involve CASTing and is quick to respond:

DATEADD(DAY, 0, DATEDIFF(DAY, 0, <ColumnName>))

Here is how it works: Whether smalldatetime or datetime, DATEDIFF(DAY, 0 returns the number of days since the base date, and DATEADD(DAY, 0 returns the integer as a date value.

Neat, isn’t it ?

Advertisements

Timeline

October 2017
M T W T F S S
« Mar    
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Blog Stats

  • 42,939 hits