Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Date Format in Csv File - US and UK Format

Posted on 2009-06-29
7
Medium Priority
?
512 Views
Last Modified: 2013-11-30
Hi

I have a file csv file, sometimes the date is in UK and sometimes it is US Format.
The file is loaded onto SQL Server using DTS, how do you detect if the date is US or UK so to convert it in the correct format.
I know that the below converts from US to UK, but I need something to detect it row by row and then convert it accordinarly
CONVERT(datetime, MIFL.[Report Date], 101) as 'RepDate',

Any help will be great.
0
Comment
Question by:ITHELPME
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 2

Expert Comment

by:allie
ID: 24737754
As far as I know, if you're working with a .csv file, and the date format can be different from one row to the next, there is no way to automatically determine if it's US or UK.  There's just no way to look at the text like '03/04/2009' and know if it's March 4th or April 3rd.

Is it possible to get the date in MMM-dd-YYYY format, like 'APR-03-2009', which could be standardized?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24741633
>>The file is loaded onto SQL Server using DTS, how do you detect if the date is US or UK so to convert it in the correct format.<<
You can't.  The best you can do is load the data in a staging table (I trust you are already doing that) as character data and check then.
0
 

Author Comment

by:ITHELPME
ID: 24743336
I am loading it into a staging table but how do I check it and convert it from here
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24744466
Are all the dates in one format or the other?  Or could each row be different?
0
 
LVL 30

Accepted Solution

by:
nmcdermaid earned 1500 total points
ID: 24760448
Are yuo looking at the CSV in Excel or notepad? Excel applies its own formatting and that clouds the issue. Look at it in notepad and see if it really does change formats. Unless your source system specifically stores them in this ambiguous format then I would be suprised if the format does change within the file.
Basically there is no way to tell if 01-02-09 is 1st Feb 09 or 2nd Jan 09 unless you have something telling you what format it is.
Why don't you post some example data.
0
 

Author Comment

by:ITHELPME
ID: 24762991
When I created the temp table, I created it as DateTime, I changed this to Varchar(50) and import the data from the file, then I do a convert when extracting the data accross.
Thanks for all your help!
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24763211
You are welcome.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question