|
|
Question : return date format yyyyMMdd
|
|
I want to return the current date in the format yyyyMMdd.
I have this formula currently, which works well EXCEPT, that id doesn't add leading zeros. I would like to add leading zeros, in front of the month and day when they are only one digit. For example I would like to return the string '20060106' for todays date.
( select cast(year(getdate()) as varchar(4)) + cast(month(getdate()) as varchar(2)) + cast(day(getdate()) as varchar(2)))
|
Answer : return date format yyyyMMdd
|
|
why not simply this: select convert(char(8), getdate(), 112)
|
|
|
|
|