January 2, 2008 at 3:28 pm
How to get date part of the dateTime without converting it into a string because when I order by such string I do not get correct order if dates are for different years..
If I have:
2007-12-30 09:36:09.890
I need 2007-12-30 date
but I don't want to convert it into a string
CONVERT( char(10), getDate(), 101)
because I will get date as a string '01/02/2008'
and if I order by date I will get
01/02/2008
12/31/2007
though it suppose to be
12/31/2007
01/02/2008
January 2, 2008 at 3:42 pm
You could still convert to a string, use format code 112 instead of 101. It will give your date in yyyymmdd format, and will sort as you expect.
This will strip the time portion off a datetime value: dateadd(dd,datediff(dd,0,getdate()), 0)
😎
January 2, 2008 at 3:44 pm
This is probably the easiest way to do it:
select dateadd(day,datediff(day,0,'2007-12-30 09:36:09.890'),0)
January 2, 2008 at 11:56 pm
Concur... just about the fastest way, too!
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply