Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
While performing sorting in GridView this is the result:

13-Dec
19-Dec
20-Dec
14-Dec
13-Dec
10-Dec
15-Dec
16-Dec

which is not correct, instead it should be:

10-Dec
13-Dec
13-Dec
14-Dec
15-Dec
16-Dec
19-Dec
20-Dec

please help to 'Sort' this out...Also it is a DATE type column...

Code was:
SQL
SELECT status,name, dob, category FROM Family_Details 
WHERE ((DATEDIFF(dd, getdate(), DATEADD(yyyy, DATEDIFF(yyyy, dob, getdate()) + 1, dob))) % 366 <= 10)ORDER BY DESC



I also used:
SQL
SELECT status,name, dob, category FROM Family_Details 
WHERE ((DATEDIFF(dd, getdate(), DATEADD(yyyy, DATEDIFF(yyyy, dob, getdate()) + 1, dob))) % 366 <= 10) ORDER BY CONVERT(DATETIME, DOB, 103) DESC
Posted
Comments
aarif moh shaikh 10-Dec-15 2:36am    
order by DOB asc
Member 12133159 10-Dec-15 2:41am    
Not working...
Jawad Ahmed Tanoli 10-Dec-15 6:49am    
what is datatype of DOB in database ?
Member 12133159 10-Dec-15 7:03am    
Sir its already there...Date type
Anisuzzaman Sumon 10-Dec-15 13:22pm    
If it's type is date then simply

SELECT status,name, dob, category FROM Family_Details WHERE ((DATEDIFF(dd, getdate(), DATEADD(yyyy, DATEDIFF(yyyy, dob, getdate()) + 1, dob))) % 366 <= 10)
order by dob asc

1 solution

I got the correct answer:

SQL
SELECT dob FROM fd WHERE ((DATEDIFF(dd, getdate(), DATEADD(yyyy, 

DATEDIFF(yyyy, dob, getdate()) + 1, dob))) % 366 <= 10)
ORDER BY MONTH(dob)ASC ,DAY(dob) ASC


This Query will sort the Birthdays coming in next 10 days by Date...

Thanks everyone and Thanks to me too...:)
 
Share this answer
 

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