When extracting timed statistics from SQL you usually want these stats grouped by some kind of time and more often than not this time unit is days. I used to do this unnecessarily complicated by converting the dates to varchars in formats I didn’t even want and maybe even use datepart(day, datetime) if the data spanned within a month. Then the good man Sören Helenelund told me about casting to date. Neat and gives me exactly what I want:

SELECT cast(getdate() as date)

It will output the today’s date in my localized format 2013-05-30 and can be used to group things or whatever. Wonderful and easy to remember. Thanks Sören!

Why not join the newsletter?

Why not join the newsletter?

If you're not a fan of facebook or twitter, sign up to the newsletter and I'll send you a quick update every so often with what's going on and new posts coming out.

You have Successfully Subscribed!