SQL Dateformat problem

I wish to convert a datetime value to a string in the format YYYYMMDD where YYYY is the year, MM is the month with leading zero if appliccable and DD is the day, also with leading zero if appliccable.

EG. for 4th may 2006 the string would be 20060504

I am using microsoft SQL Server (2005)

Thanks,

Roger
LVL 2
alcindorAsked:
Who is Participating?
 
Kinger247Connect With a Mentor Commented:
Try : select convert(varchar(8), convert(datetime, getdate(), 112), 112)

where getdate() is your date !
0
All Courses

From novice to tech pro — start learning today.