Click here to Skip to main content
16,018,417 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i've varchar type column in my table. I store date of first visit to in it. Now i want to convert it to datetime in sql query and sort the data by date.

when i sort directly, it will sort by days only..

so how can we do that?
Posted

1 solution

Don't.
Never store date information as varchar: store it as DateTime. That way, when you user enters it is can be checked and converted using their culture info as a guide to teh format.
If you store it as a string, then every time you try to use it you have to decide if this:
12/03/05
Is 12th March 2005, or 3rd Dec 2005, or 5th March 2012, or...
Or just plain wrong:
32/01/2014


Late checking is a bad idea, and the very best solution is to change your db now, while it is still small. The later you leave it, the more problems you will get.
 
Share this answer
 
v2
Comments
TheRealSteveJudge 15-Dec-14 8:30am    
Good advice! 5*

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