?
Solved

Date Format in Csv File - US and UK Format

Posted on 2009-06-29
7
Medium Priority
?
510 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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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 ?
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

770 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