Jim Horn
asked on
Month(GetDate()) to return '04' instead of 4
Hi all
I have the following SP line in progress...
declare @time_period_id_current int
set @time_period_id_current = CAST(CAST(YEAR(GETDATE()) as char(4))+ '' + CAST(MONTH(GETDATE()) as char(4))as int)
Where I'm trying to convert the current year and month into and integer with YYYYMM format, i.e. 200604. The above line returns 20064.
How to change the above line to retain the leading '0' in the month?
Thanks in advance.
-Jim
I have the following SP line in progress...
declare @time_period_id_current int
set @time_period_id_current = CAST(CAST(YEAR(GETDATE()) as char(4))+ '' + CAST(MONTH(GETDATE()) as char(4))as int)
Where I'm trying to convert the current year and month into and integer with YYYYMM format, i.e. 200604. The above line returns 20064.
How to change the above line to retain the leading '0' in the month?
Thanks in advance.
-Jim
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Right('00' + CAST(MONTH(GETDATE()) as char(4))as int) ,2)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks guys. -Jim
Glad to be of assistance. May all your days get brighter and brighter.