aneilg
asked on
sql date format
please note the dates get added everyday and are not static.
my source table has the following date. 2011-10-04 00:00:00.000
the following code below produces the dta as follows. 041011.xls
i need to change it from ddmmyy to yyyymmdd.
my source table has the following date. 2011-10-04 00:00:00.000
the following code below produces the dta as follows. 041011.xls
i need to change it from ddmmyy to yyyymmdd.
+ CASE WHEN LEN(CONVERT(VARCHAR,DATEPART(dd,@date))) = 1
THEN '0' + CONVERT(VARCHAR,DATEPART(dd,@date))
ELSE CONVERT(VARCHAR,DATEPART(dd,@date)) END
+ CASE WHEN LEN(CONVERT(VARCHAR,DATEPART(mm,@date))) = 1
THEN '0' + CONVERT(VARCHAR,DATEPART(mm,@date))
ELSE CONVERT(VARCHAR,DATEPART(mm,@date)) END
+ CONVERT(VARCHAR,RIGHT(DATEPART(yyyy,@date),2))
+ '.xls" "exit"'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This will work for you
Select Convert(varchar,DATEPART(yyyy,'2011-01-04 00:00:00.000'))+RIGHT('00' + Convert(varchar,DATEPART(mm,' 2011-01-04 00:00:00.000')),2) + RIGHT('00' + Convert(varchar,DATEPART(dd,' 2011-01-04 00:00:00.000')),2)
date and time: don't be scared :)
https://www.experts-exchange.com/A_1499.html
https://www.experts-exchange.com/A_1499.html
ASKER
perfect
ASKER
thanks big time.