Date only datetime

Sometimes you just want a date without the time – maybe a getdate() or a datetime stored in your database. There are a couple of ways of clearing out the time, but here’s a nice conversion method I came across:

[highlighter]

So in this case getdate() would return 2010-12-31 08:29:04.973 but with the conversion to a float and back you get 2010-12-31 00:00:00.000

If you are interested to know what’s happening, basically converting the datetime to a float gave 40541.3535297839, then floor rounded it down to 40541. We then converted that back to a datetime, which gives us just the date. Yippee!

Incidentally, if you want tomorrow’s date you can use ceiling instead of floor

Leave a Reply

Your email address will not be published.