May 9, 2007 at 10:40 am
Is there away to only return the date portion of the a datetime?
May 9, 2007 at 10:55 am
SELECT DATEADD(D, 0, DATEDIFF(D, 0, GETDATE()))
IIRC, there's a slightly faster version to make this conversion (like 5% faster), but I can't recall what it is. Anyhow if you are not running this of more than a few million rows, you probably won't see any difference.
May 9, 2007 at 11:09 am
Not sure if this is it but as I recall I think this is the fastest:
SELECT DATEADD(dd, CONVERT(FLOAT, GETDATE()), 0)
May 9, 2007 at 11:30 am
I can foresee hundreds of replies to this thread...so I'll give you the best answer now before anyone beats me to it. 😛
select convert(varchar(10), getdate(), 101)
Cheers!
-Ben
Ben Sullins
bensullins.com
Beer is my primary key...
May 9, 2007 at 11:44 am
Ben, run all 3 versions of your code and see for yourself. Even at 10 000 rows, the convert will most likely be constantly slower. At millions it's not even worth testing.
May 9, 2007 at 11:56 am
A couple of things I forgot to mention.
It can't return the time in the format 00:00:00.000 and the date must be in format YYYY/MM/DD.
May 9, 2007 at 12:02 pm
A date is a place in time, hence you can't have a date without time. If you don't want to display the time you can either have the application hide that part, or use the convert solution posted.
May 9, 2007 at 12:12 pm
select convert(varchar(10),getdate(),111) will give you the correct result. As posted by Ninja's RGR'us this may slow things down a bit when being performed on millions of rows.
cheers,
Ben
Ben Sullins
bensullins.com
Beer is my primary key...
May 9, 2007 at 12:14 pm
Thanks everyone!
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply