Wednesday, May 30, 2007

Get Midnight DateTime in SQL

Here's a quick and easy way to get the midnight timestamp for the current day:

SELECT DATEADD(dd, DATEDIFF(dd, 0, GETDATE()), 0)

For more tricks on calculating SQL DateTimes, see http://www.databasejournal.com/features/mssql/article.php/3076421

1 comment:

RonNasty said...

Thanks, that worked perfectly.