Click here to Skip to main content
16,021,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want date in dsc order but when i tried query it shows like this

date
02/02/2015
01/01/2015
05/01/2015
06/01/2015

so how

What I have tried:

this is what i tried
acdochdr.postdate DESC

any solution?
Posted
Updated 7-Mar-16 20:12pm

1 solution

The order you show is probably not exactly what your data contained : no descending sort order will put exactly that list in exactly that order.

When you use an ORDER BY myDateColumn DESC clause, it can produce what look like the wrong results if the column is string based instead of DATE or DATETIME, because string based comparisons always work on a character by character basis, and the whole comparison is based on the difference between the first pair of different characters. So the sort order for numbers looks odd:
1
10
11
12
...
19
2
20
...

So start by checking your database and make sure you are storing everything in the most appropriate datatype before you go any further.
 
Share this answer
 
Comments
super_user 8-Mar-16 2:23am    
ok i try this ORDER BY
convert(date, account.postdate) DESC,
account.ACDOCNO ASC and this also shows me date in ascending order
OriginalGriff 8-Mar-16 3:33am    
Don't CONVERT your strings to dates - store them as DATE or DATE TIME.
The problem is that when you convert them, SQL has to "guess" what date format the date might be: 01/02/03 could be 1st Feb 2003, 2nd Jan 2003, or 3rd Feb 2001 depending on the locale it uses. And that means that the sort order will be pretty much useless!
Always convert dates to DateTime as soon as possible, while you have access to the user locale and can convert it correctly. Once it's in the DB, you lose control over where it came from, and the string version becomes pretty much useless for any practical purpose.
super_user 8-Mar-16 4:29am    
in table design datatype is datetime...
super_user 9-Mar-16 1:42am    
???????????

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900