HostWeb Forums » Microsoft Databases » microsoft.public.sqlserver.server » How to get a two-digit month value
Topic: How to get a two-digit month value
Howdy.
I'm attempting to use DATEPART to give me a two-digit month, and further, to
cast that as a nvarchar. It is rendering March as '3' instead of '03'.
Is there a way to get '03' here????
Thanks.
Danny
Replies below ↓
Replies
How to get a two-digit month value
Howdy.
I'm attempting to use DATEPART to give me a two-digit month, and further, to
cast that as a nvarchar. It is rendering March as '3' instead of '03'.
Is there a way to get '03' here????
Thanks.
Danny
Re: How to get a two-digit month value
Try:
select
replace (str (datepart (mm, getdate ()), 2), ' ', '0')
--
Tom
----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau
"Danny" <Danny@discussions.microsoft.com> wrote in message
news:DBD73AE0-D3A5-4747-A703-F9AE99B28633@microsoft.com...
Howdy.
I'm attempting to use DATEPART to give me a two-digit month, and further, to
cast that as a nvarchar. It is rendering March as '3' instead of '03'.
Is there a way to get '03' here????
Thanks.
Danny
Re: How to get a two-digit month value
Try:
select
replace (str (datepart (mm, getdate ()), 2), ' ', '0')
--
Tom
----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau
"Danny" <Danny@discussions.microsoft.com> wrote in message
news:DBD73AE0-D3A5-4747-A703-F9AE99B28633@microsoft.com...
Howdy.
I'm attempting to use DATEPART to give me a two-digit month, and further, to
cast that as a nvarchar. It is rendering March as '3' instead of '03'.
Is there a way to get '03' here????
Thanks.
Danny
Re: How to get a two-digit month value
SELECT RIGHT('0' + RTRIM(MONTH(GETDATE())), 2);
"Danny" <Danny@discussions.microsoft.com> wrote in message
news:DBD73AE0-D3A5-4747-A703-F9AE99B28633@microsoft.com...
> Howdy.
>
> I'm attempting to use DATEPART to give me a two-digit month, and further,
> to
> cast that as a nvarchar. It is rendering March as '3' instead of '03'.
>
> Is there a way to get '03' here????
>
> Thanks.
>
> Danny