Skip to content


SQL DateTime without the time!

Ever needed a way of returning today’s date without returning the time portion as well? I do.

Here goes:

SELECT CAST(ROUND(CAST(getdate() AS real),0,1) AS datetime)

So instead of getdate() returning something like “2006-07-24 16:48:29.910″, this nifty little function gives you it to you like “2006-07-24 00:00:00.000″.

Tested using MSSQL 2005.

Posted in Software.

Tagged with .


4 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. BBCoder says

    This will run faster and have less errors:
    SELECT CAST(CAST(getdate() as int) as datetime)

    The datetime field is stored as 4 byte integers. And looks like “date.time” with the time as the decimal. Casting as an int causes the decimal to drop off giving a true time.

  2. BasicPgrmr says

    The example from BBCoder
    “SELECT CAST(CAST(getdate() as int) as datetime)”
    only works if it’s early in the day. Running this can round the date up to the following day, thereby returning wrong data.

  3. Meribah says

    U can also try this…
    Select cast(getdate() as varchar(12))

    This returns MMM dd yyyy eg Mar 28 2008 in Sql server 2000

  4. Tim says

    Great code this worked awesome. Exactly what I was looking for.



Some HTML is OK

or, reply to this post via trackback.