Jeremy Stein - Brain

« »

SQL Server – truncate time from Date

In T-SQL, the easiest way to truncate a DateTime field (to get the date with midnight as its time) is this:

CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME)

But I’ve also seen it done this way:

CONVERT(VARCHAR(10), GETDATE(), 111) — just treat this as a datetime

February 6, 2007 No Comments.

No Comments

Be the first to comment!

Leave a Reply

Your email address will not be published. Required fields are marked *

Why ask?

« »