Solved

Date Format in Csv File - US and UK Format

Posted on 2009-06-29
7
494 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
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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

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