Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 Date format conversion

Author  Topic 

varalakshmi
Yak Posting Veteran

98 Posts

Posted - 2010-05-10 : 03:15:30
Hi,

My table should store date in the 'ddmmyyyy' format.
But data has been loaded with 'mmddyyyy' format.
Hence the data in the table is currently wrong.

Eg: Instead of storing the date as April 1st, data is stored as Jan 4th.

How can this be corrected in the database?

-Varalakshmi

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-10 : 04:06:52
1 Use proper DATETIME dataype to store dates
2 When sending dates to table, express them in YYYYMMDD format
3 Let your front end application do formation for display

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

varalakshmi
Yak Posting Veteran

98 Posts

Posted - 2010-05-10 : 04:35:57
The data is already loaded in to the DB worngly.
How can this be corrected now?
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-05-10 : 04:42:45
Whats the datatype of the column is it Varchar?

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-05-10 : 04:49:18
Try this

update table_name set date_column =cast(
cast(day(date_column) as varchar(2))+'/'+cast(month(date_column) as varchar(2))+'/'+
cast(year(date_column) as varchar(4)) as datetime)

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page
   

- Advertisement -