Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How to sort string of date?

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2007-10-26 : 16:34:25
I stored date data in varchar type.
How to sort them?
If I sort desc, '2/15/2007' is before '09/06/2007' which is wrong.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-10-26 : 16:35:09
Convert it to datetime then sort.

Or fix your data so that your dates can be sorted via varchar. This would mean using two-digit months and days and four-digit years.

mm/dd/yyyy

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-10-26 : 17:23:13
"I stored date data in varchar type"

Simple answer is "Don't". There are very few reasons why storing a date in anyothing other than a datetime datatype is useful.

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-29 : 01:27:33
quote:
Originally posted by Sun Foster

I stored date data in varchar type.
How to sort them?
If I sort desc, '2/15/2007' is before '09/06/2007' which is wrong.


Why did you use varchar datatype to store date values?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -