Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using Datetime format varchar method.in my db stored two format 22/01/2011 and 01-Apr-2011 . how to retrieve both format in C#.net.


regards
......
Posted

1 solution

Do not store dates in your DB as Varchar - always store them as Date or DateTime. That way, the date is culture independent, and you can do math with it: sorting by date for example only works properly with Date or DateTime, it is culture dependant and silly orders for varchar, because "Feb" comes before "Jan" for example.

When you get a date convert it immediately to DateTime in C#, when you output dates, leave it to the last moment to convert it back to a string. That way your inputs should be in the current user culture (which keeps him happy) and your outputs can be in a different culture format if required (which keep sthat user happy as well).
 
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