Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Such as third-party data sources stored in the "03/05/14" date format,
I need to put the date into a "2014/05/03", how do I do it

SQL Server Example

Source data: '03/05/14'

Transformation methods:
SQL
select convert(datetime, '03/05/14', 3)


Result:2014-05-03 00:00:00.000
Posted
Comments
Maciej Los 3-May-14 4:19am    
Are you talking about SQL Server or UI?

1 solution

Hi,

I am not sure what exactly you mean by saying "to put the date into a '2014/05/03'"...

In SQL Server, date values are stored in an internal format, not something like "DD/MM/YY", "YYYY/MM/DD", etc. But there are rules for how different datetime formats are interpreted. If you'd like to know more about it, then read this article:
The ultimate guide to the datetime datatypes[^]

Here's how to get the date in "YYYY/MM/DD" format:
1. SQL Server:
SQL
SELECT CONVERT(VARCHAR(10), GETDATE(), 111);

Result:
XML
2014/05/03


2. SSIS:
SQL
(DT_STR, 4, 1252) DATEPART("yy", GETDATE()) + "/" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm", GETDATE()), 2) + "/" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd", GETDATE()), 2)

Result:
XML
2014/05/03

I tested it with this tool:
SSIS Expression Editor & Tester[^]


Please let me know if you need something else.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900