Home All Groups Group Topic Archive Search About

What is the .NET way? - Right("0" & Now.Month.ToString, 2)

Author
18 Aug 2006 4:49 PM
Terry Olsen
This is the easiest way I can think of to do this:
tmp=Right("0" & Now.Month.ToString, 2)

The only way I've figured to do it the .NET way is this:
tmp="0" & Now.Month.ToString
tmp=tmp.substring(tmp.length-3)

Surely, there's a more elegant way?


*** Sent via Developersdex http://www.developersdex.com ***

Author
18 Aug 2006 5:02 PM
Michael D. Ober
tmp = now.month.tostring("00") should do the trick.

Mike.

Show quoteHide quote
"Terry Olsen" <tolse***@hotmail.com> wrote in message
news:%23kykMZuwGHA.4460@TK2MSFTNGP04.phx.gbl...
>
> This is the easiest way I can think of to do this:
> tmp=Right("0" & Now.Month.ToString, 2)
>
> The only way I've figured to do it the .NET way is this:
> tmp="0" & Now.Month.ToString
> tmp=tmp.substring(tmp.length-3)
>
> Surely, there's a more elegant way?
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
Author
18 Aug 2006 5:06 PM
Tom Dacon
Now.ToString("MM")

Go to DateTime.ToString in the help file and start following links around
until you find the table of datetime format strings.

Tom Dacon
Dacon Software Consulting

Show quoteHide quote
"Terry Olsen" <tolse***@hotmail.com> wrote in message
news:%23kykMZuwGHA.4460@TK2MSFTNGP04.phx.gbl...
>
> This is the easiest way I can think of to do this:
> tmp=Right("0" & Now.Month.ToString, 2)
>
> The only way I've figured to do it the .NET way is this:
> tmp="0" & Now.Month.ToString
> tmp=tmp.substring(tmp.length-3)
>
> Surely, there's a more elegant way?
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
Author
18 Aug 2006 5:18 PM
Cor Ligthert [MVP]
In addition to Tom,

The IFormatProvider for dates

http://msdn2.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx

I hope this helps,

Cor

Show quoteHide quote
"Terry Olsen" <tolse***@hotmail.com> schreef in bericht
news:%23kykMZuwGHA.4460@TK2MSFTNGP04.phx.gbl...
>
> This is the easiest way I can think of to do this:
> tmp=Right("0" & Now.Month.ToString, 2)
>
> The only way I've figured to do it the .NET way is this:
> tmp="0" & Now.Month.ToString
> tmp=tmp.substring(tmp.length-3)
>
> Surely, there's a more elegant way?
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
Author
18 Aug 2006 5:53 PM
Herfried K. Wagner [MVP]
"Terry Olsen" <tolse***@hotmail.com> schrieb:
> This is the easiest way I can think of to do this:
> tmp=Right("0" & Now.Month.ToString, 2)
>
> The only way I've figured to do it the .NET way is this:
> tmp="0" & Now.Month.ToString
> tmp=tmp.substring(tmp.length-3)
>
> Surely, there's a more elegant way?

\\\
MsgBox(Now.ToString("MM"))
MsgBox(Now.Month.ToString("D2"))
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
18 Aug 2006 6:05 PM
Cor Ligthert [MVP]
Herfried,

Tom (and I) were trying to teach Terry how to fish, we probably both know
how we have to give that fish.

:-)

Cor

Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schreef in bericht
news:uLfEy8uwGHA.4280@TK2MSFTNGP04.phx.gbl...
> "Terry Olsen" <tolse***@hotmail.com> schrieb:
>> This is the easiest way I can think of to do this:
>> tmp=Right("0" & Now.Month.ToString, 2)
>>
>> The only way I've figured to do it the .NET way is this:
>> tmp="0" & Now.Month.ToString
>> tmp=tmp.substring(tmp.length-3)
>>
>> Surely, there's a more elegant way?
>
> \\\
> MsgBox(Now.ToString("MM"))
> MsgBox(Now.Month.ToString("D2"))
> ///
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>