Have you ever been irritated by the lack of a function in SQL server that returns
only a date, here are two SQL scripts that can be used to return just the date part.
You can use the good old faithful CONVERT function, which was the first thing that
sprung to my mind, like this:
SELECT CONVERT(datetime, CONVERT(varchar(10), getdate(), 101))
>
The one fear I have with the script above is that it may be affected
by the machines locale. While I've been told that SQL always correctly interprets
YYYYMMDD, I've only ever tested against UK, US and South African locales which
hardly makes that assumption conclusive.
Another approach, which is far safer and the one I'd recommend,
is to use DateAdd:
SELECT DATEADD(dd, DATEDIFF(dd,0,getdate()), 0)
So how, does this work? Well when 0 is converted to a datetime value, it is interpreted
as 1 Jan 1900 00:00:00. So the SQL above first gets the difference in days between
today and the 1 Jan 1900 and then adds that difference back 1 Jan 1900, thereby removing
the time component.