Link to home
Start Free TrialLog in
Avatar of aneilg
aneilgFlag for United Kingdom of Great Britain and Northern Ireland

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.
+ 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"'

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Eyal
Eyal
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aneilg

ASKER

dude your a Ledged. i hate dates. saved me so much messing round. got deadlines to meet.

thanks big time.
Avatar of pritamdutt
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) 

Open in new window

Avatar of aneilg

ASKER

perfect