 |
|
 |
|
Next: ROLLUP without GROUP BY?
|
| Author |
Message |
External

Since: Sep 17, 2007 Posts: 16
|
(Msg. 1) Posted: Tue Jun 10, 2008 12:23 pm
Post subject: How to get a two-digit month value Archived from groups: microsoft>public>sqlserver>server (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Jan 10, 2008 Posts: 640
|
(Msg. 2) Posted: Tue Jun 10, 2008 2:10 pm
Post subject: Re: How to get a two-digit month value [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Jun 10, 2:23 pm, Danny 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
SELECT RIGHT(CAST(100 + MONTH(GetDate()) AS CHAR(3)),2) >> Stay informed about: How to get a two-digit month value |
|
| Back to top |
|
 |  |
External

Since: Apr 21, 2004 Posts: 502
|
(Msg. 3) Posted: Tue Jun 10, 2008 3:31 pm
Post subject: Re: How to get a two-digit month value [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
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" wrote in message
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 >> Stay informed about: How to get a two-digit month value |
|
| Back to top |
|
 |  |
|
Aaron Bertrand [SQL Serve
|
External

Since: Jan 10, 2008 Posts: 2166
|
(Msg. 4) Posted: Tue Jun 10, 2008 3:52 pm
Post subject: Re: How to get a two-digit month value [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
SELECT RIGHT('0' + RTRIM(MONTH(GETDATE())), 2);
"Danny" wrote in message
> 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 >> Stay informed about: How to get a two-digit month value |
|
| Back to top |
|
 |  |
External

Since: Sep 17, 2007 Posts: 16
|
(Msg. 5) Posted: Tue Jun 10, 2008 3:52 pm
Post subject: Re: How to get a two-digit month value [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
yes, this works. Thank you Aaron.
"Aaron Bertrand [SQL Server MVP]" wrote:
> SELECT RIGHT('0' + RTRIM(MONTH(GETDATE())), 2);
>
>
> "Danny" wrote in message
>
> > 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
>
>
> >> Stay informed about: How to get a two-digit month value |
|
| Back to top |
|
 |  |
External

Since: Sep 17, 2007 Posts: 16
|
(Msg. 6) Posted: Wed Jun 11, 2008 3:05 pm
Post subject: RE: How to get a two-digit month value [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Thank you all for your help - greatly appreciated.
"Danny" 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 >> Stay informed about: How to get a two-digit month value |
|
| Back to top |
|
 |  |
External

Since: Sep 09, 2003 Posts: 255
|
(Msg. 7) Posted: Wed Jun 11, 2008 11:49 pm
Post subject: Re: How to get a two-digit month value [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Jun 10, 2011 Posts: 1
|
(Msg. 8) Posted: Fri Jun 10, 2011 3:25 pm
Post subject: Re: Re: How to get a two-digit month value [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Thank, Alex. I liked your solution and it worked great!
> 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
>> 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" wrote in message
>>
>> 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
>>> On Tuesday, June 10, 2008 3:52 PM Aaron Bertrand [SQL Server MVP] wrote:
>>> SELECT RIGHT('0' + RTRIM(MONTH(GETDATE())), 2);
>>>> On Tuesday, June 10, 2008 5:38 PM Dann wrote:
>>>> yes, this works. Thank you Aaron.
>>>>
>>>> "Aaron Bertrand [SQL Server MVP]" wrote:
>>>>> 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
>>>>>> On Wednesday, June 11, 2008 6:05 PM Dann wrote:
>>>>>> Thank you all for your help - greatly appreciated.
>>>>>>
>>>>>> "Danny" wrote:
>>>>>>> On Thursday, June 12, 2008 11:27 PM Alex Kuznetsov wrote:
>>>>>>> SELECT RIGHT(CAST(100 + MONTH(GetDate()) AS CHAR(3)),2)
>>>>>>>> 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 >> Stay informed about: How to get a two-digit month value |
|
| Back to top |
|
 |  |
External

Since: Aug 04, 2011 Posts: 1
|
(Msg. 9) Posted: Thu Aug 04, 2011 10:25 am
Post subject: Re: Re: Re: How to get a two-digit month value [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Hey it's not more easy just use:
SELECT CONVERT(VARCHAR(12), getdate(), 112)
> 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
>> 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" wrote in message
>>
>> 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
>>> On Tuesday, June 10, 2008 3:52 PM Aaron Bertrand [SQL Server MVP] wrote:
>>> SELECT RIGHT('0' + RTRIM(MONTH(GETDATE())), 2);
>>>> On Tuesday, June 10, 2008 5:38 PM Dann wrote:
>>>> yes, this works. Thank you Aaron.
>>>>
>>>> "Aaron Bertrand [SQL Server MVP]" wrote:
>>>>> 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
>>>>>> On Wednesday, June 11, 2008 6:05 PM Dann wrote:
>>>>>> Thank you all for your help - greatly appreciated.
>>>>>>
>>>>>> "Danny" wrote:
>>>>>>> On Thursday, June 12, 2008 11:27 PM Alex Kuznetsov wrote:
>>>>>>> SELECT RIGHT(CAST(100 + MONTH(GetDate()) AS CHAR(3)),2)
>>>>>>>> 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
>>>>>>>>> On Friday, June 10, 2011 3:05 PM Amber Fontes wrote:
>>>>>>>>> Thank, Alex. I liked your solution and it worked great! >> Stay informed about: How to get a two-digit month value |
|
| Back to top |
|
 |  |
| Related Topics: | Last day of month - If I keep a hard sql statment to show all records from 1 to 31 of each month will get error on months where there are no 31 days, how can i know the last day of the month ? any sql function or just via programming language? Thanks!
reporting between dates 26th of a month to 25th of the nex.. - I am trying to report on cases gievn to our business but the date parameter has to be from the 26th of the previous month to the 25th of the current month. The report will be schduled to run on the 26th of each month. I am unsure as to how best to go..
DateAdd function on 30th and 31st of month - Hi Everyone, When I run the dateadd function adding months on 30th and 31st of any months returns the same result. I am OK with that because logically it is correct. If I have to do a reverse lookup for the date, how can I do that. Here is the code..
Insert output of procedure inside table - Hello, Can you tell me how can i put the output if the procedure sp_helpdb inside one table? Thanks and best regards
SQL Agent won't start - Our installation of SQLServer 2000 has been working fine until last week when SQLAgent cannot start due to a login problem with SQLServer. SQLAgent properties have not changed since the problem began, but the event log reports that SQLAgent cannot log... |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|