April 16, 2002 at 12:19 pm
I have defined a variable "@varMonth char(2)", and then initialized it with the line:
SET @varMonth = DATEPART(Month, @varSysDate).
The problem is, this returns a "4" for April, not an "04". How can I get it to return "04"? I know I could just concatenate a "0" to the beginning of the value, but that isn't the way I want to do it.
I want it to return the month as 2-digits, no matter what month it is, and I'd prefer not to specifically define it differently for Oct-Dec.
April 16, 2002 at 12:28 pm
How about
select @varMonth =left(convert(varchar(10),@varSysDate,101),2)
see CONVERT (data_type[(length)], expression [, style])
where 101 is -"mm/dd/yy"
Edited by - EPol29 on 04/16/2002 12:30:44 PM
April 16, 2002 at 12:31 pm
perfect. thanks
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply