Solved

Date Format in Csv File - US and UK Format

Posted on 2009-06-29
7
507 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
Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

 
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 500 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

726 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