So I have an Excel file with values as 19/09/2011 on a column called “Dates”. I selected the entire column in Excel – Format cells – Location: English(UK) and selected the sample value of “14/03/2011” so that the day appears before the month.
Now, using a simple import package in Visual Studio, I imported the data in Sql Server (I used 3 tasks generated by the wizard: Drop table, create table structure in Sql Server, and actual import).
In the create table task, I specified the dates column type as date.
After that, to test the outcome, I selected dates in the Sql Server table ordering it by dates desc.
So I get this, all rumble-jumbled (this is supposed to be only September data, so we should have only “09” after the year):
2011-12-09
2011-11-09
2011-10-09
2011-09-30
2011-09-29
2011-09-28
2011-09-27
2011-09-26
2011-09-25
2011-09-24
2011-09-23
2011-09-22
2011-09-21
2011-09-20
2011-09-19
2011-09-18
2011-09-17
2011-09-16
2011-09-15
2011-09-14
2011-09-13
2011-09-09
2011-08-09
2011-07-09
2011-06-09
2011-05-09
2011-04-09
2011-03-09
2011-02-09
2011-01-09
To get data into a datetime column you can:
as strings in the format of yyyymmdd such as
20120928can always be cast to datetime regardless of the format settings (as they are a certain ISO format).To get data out of a table in a particular format you can either
CASTorCONVERTor usee.g.
EDIT: using convert would look like this:
which returns: