2 pages: [1] [2]
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

Reply | New Topic | This is SPAM | This is Offensive

Submitted: 6/10/2008 1:23:01 PM

By: Anonymous
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

Reply | New Topic | This is SPAM | This is Offensive

Submitted: 6/10/2008 1:23:01 PM

By: Anonymous

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

Reply | New Topic | This is SPAM | This is Offensive

Submitted: 6/10/2008 1:31:46 PM

By: Tom Moreau

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



Reply | New Topic | This is SPAM | This is Offensive

Submitted: 6/10/2008 1:31:46 PM

By: Tom Moreau

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



Reply | New Topic | This is SPAM | This is Offensive

Submitted: 6/10/2008 1:52:42 PM

By: Aaron Bertrand [SQL Server MVP]

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



Contents
Home
Forums
About Us
Contact Us
Web Hosting:
Hosting Providers
How to choose a name
What is a Hosting Provider
Hosting Types
Choosing the right plan
 
Search
 
Login to HostWeb.com
Email
Password
If you do not have an account with us yet, join now - it's FREE!