SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date Formatting
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Grifter
Posting Yak Master

214 Posts

Posted - 05/10/2012 :  06:41:49  Show Profile  Reply with Quote
Hi

In one of our DBs we ended up with imported dates from another system and I basically need to format these so they are all the same. The system they came from was changed frequently and we had a lot of trouble because they were sending us strings with dates formatted all over the place.

I now have these 3 distinct formats in a column:

null
dd/mm/yyyy
mmm dd yyyy 12:00AM

And I want to change the last date/time format one to dd/mm/yyyy, and also is there a way to check these strings for data that would not normally be in a date format such as dd/mm/yyyy*, so I would be able to recognise only the data and clear out any rubbish in the string.

Don't ask why the imported values were not from date fields, I asked the developer and they said it made it easier for them to import them from the sales system!! however a nightmare on our side as we keep running into date formatting problems as we try to fix the strings into a proper date format.

G

Grifter
Posting Yak Master

214 Posts

Posted - 05/10/2012 :  07:01:39  Show Profile  Reply with Quote
This worked for me but how do I then convert to a proper format:

select distinct CONVERT(DATE, MyDatefield, 103) AS MyDatefield
from all_data


As in my returned dates are now yyyy-MM-dd

Do I need to convert back to string and format as dd/mm/yyyy??

G
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22460 Posts

Posted - 05/10/2012 :  07:04:17  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote

select convert(varchar(10),cast('jan 16 2007 12:00AM' as datetime) ,103)

But Import data into staging table and move data to source table by converting VARCHARs to DATETIME and use column with DATETIME datatype

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000