Click here to Skip to main content
15,886,858 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a table column Plaerdob witch have diff date type like
1- 1-jan-1987.
2- 01/01/1987
3- 01-jan-1987.

Here i want to update all my dates format of 2 and 3 into 1.

Can it be possible? if yes then how?

Pls help.

Thanks
Posted

Simple: don't store date information as strings - always store it as DATE or DATETIME values instead.
The problem is that there are a huge number of ways to enter a date, and they are all equaly valid.
Unfortunately, you can't tell just by looking at the string which date it is:
01/02/03  Could be 1st Feb 2003  (Europe)
          Could be 2nd Jan 2003  (US)
          Could be 3rd Feb 2001  (Japan)
So by the time the string has arrived at your database, it's too late - all the information you need to work out what the date is has been discarded: it was most likely to be defined by the Culture that the PC the user you entered it was set to.
And what are you supposed to do with "1-avr-1987" (French)? Or "1-ian-1987" (German)?

You may be able to convert it by reading your whole DB into C# and using DateTime.TryParse to convert them to DateTime values and then updating a new column, but even then the examples above will all be assumed to be in the culture of the PC you app is running on.

So the answer is: Yes, but it won't be reliable, and it will almost certainly contain errors.

Change your DB to use Date based fields - and never store them as strings again.
 
Share this answer
 
SQL
SELECT CONVERT(VARCHAR, GETDATE(), 106) -- 04 May 2013
SELECT CONVERT(DATETIME, '04 May 2013', 106) -- 2013-05-04 00:00:00.000


We have a great article . Please read SQL Server Functions that helps to convert date and time values to and from string literals and other date and time formats.[^]
 
Share this answer
 
hi OriginalGriff,
I know these things but it already done and there are 6000+ profiles and i dont know how many times these column used.
So i cant think to change this type as of now, just have to think about the alternate.

thanks
 
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