Showing posts with label ordered. Show all posts
Showing posts with label ordered. Show all posts

Monday, February 20, 2012

Problem with dates

My dilema would probably be nothing to some of you guys but I'm still new to tsql. I have a bunch of info that I need to have ordered by date. I have tried the following:

ORDER BY Due_Date DESC

I have my dates returned in the format : dd/mm/yyyy

But it only orders the days not months or years.

heres the output:

28/02/2004
20/02/2004
19/02/2004
10/12/2003 // as you can see this one should be at the top
05/02/2004
05/02/2004
05/02/2004
13/02/2004
05/02/2004
01/02/2004

Any help would be well appreciatedIs your date field a datetime or a varchar? If a varchar, this is the reason you should not store dates as a varchar. You can try:

ORDER BY CONVERT(datetime,Due_Date) DESC

This presumes your SQL Server is set up to properly parse dates in that format.|||All of my fields are datetime.|||28/02/2004
20/02/2004
19/02/2004
10/12/2003 // as you can see this one should be at the top
05/02/2004
05/02/2004
05/02/2004
13/02/2004
05/02/2004
01/02/2004

... that's all out of order if you think it's the order by.

it's not even order bying anything.

Are you doing a group by?|||There is another post on this issue where more information was provided.view post 466200

Please do not cross-post!

Let's drop this post and concentrate our efforts on the other one since it provides a fuller picture of the problem.

Terri