Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Convert dd/mm/yy to yymmdd

Tags:

date

sql

I have been trying to achieve this all day, I have followed numerous tutorials and can't seem to crack it, I have been trying things like:

select CONVERT(VARCHAR(10), DATE, 131) from Table

yet it does not seem to change anything.

Any advice or help would be appreciated. Thankyou in advance.

like image 841
holodan Avatar asked Sep 06 '25 12:09

holodan


2 Answers

SELECT CONVERT(VARCHAR(10), DATE, 12)

12 is the right code for the format you want. See: https://msdn.microsoft.com/en-GB/library/ms187928.aspx

Try this

declare @TDATE Date = '2015-11-10';
select Convert(varchar,Datepart(Year, @TDATE))+Convert(varchar,Datepart(Month, @TDATE))+Convert(varchar,Datepart(Day, @TDATE))

Output:

20151110
like image 31
Dhaval Asodariya Avatar answered Sep 10 '25 02:09

Dhaval Asodariya