dbTalk Databases Forums  

How to get a two-digit month value

microsoft.public.sqlserver.server microsoft.public.sqlserver.server


Discuss How to get a two-digit month value in the microsoft.public.sqlserver.server forum.



Reply
 
Thread Tools Display Modes
  #61  
Old   
Danny
 
Posts: n/a

Default RE: How to get a two-digit month value - 06-11-2008 , 05:05 PM






Thank you all for your help - greatly appreciated.

"Danny" wrote:

Quote:
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 With Quote
  #62  
Old   
Danny
 
Posts: n/a

Default RE: How to get a two-digit month value - 06-11-2008 , 05:05 PM






Thank you all for your help - greatly appreciated.

"Danny" wrote:

Quote:
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 With Quote
  #63  
Old   
Danny
 
Posts: n/a

Default RE: How to get a two-digit month value - 06-11-2008 , 05:05 PM



Thank you all for your help - greatly appreciated.

"Danny" wrote:

Quote:
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 With Quote
  #64  
Old   
Danny
 
Posts: n/a

Default RE: How to get a two-digit month value - 06-11-2008 , 05:05 PM



Thank you all for your help - greatly appreciated.

"Danny" wrote:

Quote:
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 With Quote
  #65  
Old   
Danny
 
Posts: n/a

Default RE: How to get a two-digit month value - 06-11-2008 , 05:05 PM



Thank you all for your help - greatly appreciated.

"Danny" wrote:

Quote:
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 With Quote
  #66  
Old   
Danny
 
Posts: n/a

Default RE: How to get a two-digit month value - 06-11-2008 , 05:05 PM



Thank you all for your help - greatly appreciated.

"Danny" wrote:

Quote:
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 With Quote
  #67  
Old   
Danny
 
Posts: n/a

Default RE: How to get a two-digit month value - 06-11-2008 , 05:05 PM



Thank you all for your help - greatly appreciated.

"Danny" wrote:

Quote:
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 With Quote
  #68  
Old   
Amber Fontes
 
Posts: n/a

Default Re: Re: How to get a two-digit month value - 06-10-2011 , 02:05 PM



Thank, Alex. I liked your solution and it worked great!

Quote:
On Tuesday, June 10, 2008 3:23 PM Dann wrote:

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

Quote:
On Tuesday, June 10, 2008 3:31 PM Tom Moreau wrote:

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 (AT) discussions (DOT) microsoft.com> wrote in message
newsBD73AE0-D3A5-4747-A703-F9AE99B28633 (AT) microsoft (DOT) 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

Quote:
On Tuesday, June 10, 2008 3:52 PM Aaron Bertrand [SQL Server MVP] wrote:

SELECT RIGHT('0' + RTRIM(MONTH(GETDATE())), 2);

Quote:
On Tuesday, June 10, 2008 5:38 PM Dann wrote:

yes, this works. Thank you Aaron.

"Aaron Bertrand [SQL Server MVP]" wrote:

Quote:
On Wednesday, June 11, 2008 5:49 PM Gert-Jan Strik wrote:

Yet another solution:

SELECT SUBSTRING(CONVERT(nvarchar(6), CURRENT_TIMESTAMP, 112),5,2)

--
Gert-Jan
SQL Server MVP

Quote:
On Wednesday, June 11, 2008 6:05 PM Dann wrote:

Thank you all for your help - greatly appreciated.

"Danny" wrote:

Quote:
On Thursday, June 12, 2008 11:27 PM Alex Kuznetsov wrote:

SELECT RIGHT(CAST(100 + MONTH(GetDate()) AS CHAR(3)),2)

Quote:
On Thursday, March 12, 2009 11:18 AM Ryan Tomlinson wrote:

After looking at several solutions online, yours was by far the simplest and best.

Thanks,
Ryan

Reply With Quote
  #69  
Old   
Alexander Matos
 
Posts: n/a

Default Re: Re: Re: How to get a two-digit month value - 08-04-2011 , 08:47 AM



Hey it's not more easy just use:

SELECT CONVERT(VARCHAR(12), getdate(), 112)

Quote:
On Tuesday, June 10, 2008 3:23 PM Dann wrote:

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

Quote:
On Tuesday, June 10, 2008 3:31 PM Tom Moreau wrote:

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 (AT) discussions (DOT) microsoft.com> wrote in message
newsBD73AE0-D3A5-4747-A703-F9AE99B28633 (AT) microsoft (DOT) 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

Quote:
On Tuesday, June 10, 2008 3:52 PM Aaron Bertrand [SQL Server MVP] wrote:

SELECT RIGHT('0' + RTRIM(MONTH(GETDATE())), 2);

Quote:
On Tuesday, June 10, 2008 5:38 PM Dann wrote:

yes, this works. Thank you Aaron.

"Aaron Bertrand [SQL Server MVP]" wrote:

Quote:
On Wednesday, June 11, 2008 5:49 PM Gert-Jan Strik wrote:

Yet another solution:

SELECT SUBSTRING(CONVERT(nvarchar(6), CURRENT_TIMESTAMP, 112),5,2)

--
Gert-Jan
SQL Server MVP

Quote:
On Wednesday, June 11, 2008 6:05 PM Dann wrote:

Thank you all for your help - greatly appreciated.

"Danny" wrote:

Quote:
On Thursday, June 12, 2008 11:27 PM Alex Kuznetsov wrote:

SELECT RIGHT(CAST(100 + MONTH(GetDate()) AS CHAR(3)),2)

Quote:
On Thursday, March 12, 2009 11:18 AM Ryan Tomlinson wrote:

After looking at several solutions online, yours was by far the simplest and best.

Thanks,
Ryan

Quote:
On Friday, June 10, 2011 3:05 PM Amber Fontes wrote:

Thank, Alex. I liked your solution and it worked great!

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.