Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi i want to save date in sql 2005 in custom format
like aug 2011 week 3
something like that i need some help
Posted
Comments
Mario Majčica 22-Aug-11 17:16pm    
Why should you do that?

1 solution

Formatting is not part of the date data type in SQL server.

Your options are along the lines of the following:
1) Use varchar(20), stored procs and views to format and persist the date as text
2) Format the date on the client.

Number 2 is the much better solution as you still get the benefit of sorting, data size etc. with SQL server.

You can view the MSDN docs on date formatting here.[^]

Cheers.
 
Share this answer
 
Comments
Philippe Mori 22-Aug-11 19:39pm    
Exactly... You store date and time in SQL using datetime (or smalldatetime) format. Any formatting is done on the UI for display purpose. By the way, in the database, you should also store UTC time and then convert them to local time when displaying.
walterhevedeich 22-Aug-11 19:58pm    
Good Advice.

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