Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys i have Table with Work_date(mm/dd/yyy) column as

SQL
id    work_date

1     1/2/2011
2     1/4/2011
3     5/10/2011
4     10/1/2012


But i want to update this work_date column as

SQL
id    work_date

1     01/02/2011
2     01/04/2011
3     05/10/2011
4     10/01/2012


Means i want to add Zero (0) if month/date is less than 10. So if any body have an idea kindly share to me.
Posted
Updated 4-Dec-12 2:32am
v2
Comments
Mycroft Holmes 5-Dec-12 3:09am    
Listen to Andre, DON'T STORE YOUR DATE AS CHARACTER, this is one of the most basic errors you can make in database design. When you extract the DateTime data from the table is when you format it using the convert.

1 solution

You really should consider changing the type of the work_date field to date[^] or datetime[^].
This will give you much more flexibility in using the data and allowing you to display the date in the format as specified by the user.

But to do what you want use the following UPDATE query:
SQL
UPDATE myTable
SET work_date = CONVERT( NCHAR(10), CONVERT( DATE, work_date, 101), 101)

First the text is converted[^] into a date, which in turn is converted back into a string.
 
Share this answer
 
Comments
Mas11 4-Dec-12 10:35am    
Thanks for reply !!

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