SQL : Get date part from datetime

I have been doing a bit of SQL stuff lately for my current project and did a lot of datetime conversion. I have always used the following query to get the date part of a datetime (which works just fine for me)

Select Convert(datetime, Convert(varchar(10), getdate(), 101))

I stumbled upon the following query which returns the same result and I find it quite interesting, that is no conversion required… 🙂

Select Dateadd(dd, 0, DateDiff(dd, 0, getdate()))

I have not seen any difference in terms of performance and it works the same with the first query. Thoughts anyone?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: