Home All Groups Group Topic Archive Search About

Convert Now to a string

Author
26 Sep 2006 1:31 AM
Laurence
In VS.2005 using VB.NET

I have tried to make a string

dim abc as string
abc = format(now,"mm/dd/yyyy")
or
abc format$(now,"mm/dd/yyyy")

but it doesn't work.

I get:  28/25/2006

the day and year are ok, but the month is always wrong,
the month is something different every time,

Thanks in Advance,

Laurence

Author
26 Sep 2006 2:21 AM
Greg
Show quote Hide quote
"Laurence" <Someth***@Something.com> wrote in message
news:uAYJPuQ4GHA.3644@TK2MSFTNGP03.phx.gbl...
> In VS.2005 using VB.NET
>
> I have tried to make a string
>
> dim abc as string
> abc = format(now,"mm/dd/yyyy")
> or
> abc format$(now,"mm/dd/yyyy")
>
> but it doesn't work.
>
> I get:  28/25/2006
>
> the day and year are ok, but the month is always wrong,
> the month is something different every time,
>
> Thanks in Advance,
>
> Laurence

mm = Minute
MM = Month

Cheers.
Author
26 Sep 2006 2:47 AM
wilson
Use MM for month with leading zero.
mm is minute with leading zero.

Laurence wrote:

Show quoteHide quote
> In VS.2005 using VB.NET
>
> I have tried to make a string
>
> dim abc as string
> abc = format(now,"mm/dd/yyyy")
> or
> abc format$(now,"mm/dd/yyyy")
>
> but it doesn't work.
>
> I get:  28/25/2006
>
> the day and year are ok, but the month is always wrong,
> the month is something different every time,
>
> Thanks in Advance,
>
> Laurence



--
Author
26 Sep 2006 4:57 PM
Laurence
Thank You,

Laurence

wilson wrote:
Show quoteHide quote
> Use MM for month with leading zero.
> mm is minute with leading zero.
>
> Laurence wrote:
>
>> In VS.2005 using VB.NET
>>
>> I have tried to make a string
>>
>> dim abc as string
>> abc = format(now,"mm/dd/yyyy")
>> or
>> abc format$(now,"mm/dd/yyyy")
>>
>> but it doesn't work.
>>
>> I get:  28/25/2006
>>
>> the day and year are ok, but the month is always wrong,
>> the month is something different every time,
>>
>> Thanks in Advance,
>>
>> Laurence
>
>
>
Author
26 Sep 2006 3:24 AM
GhostInAK
Hello Laurence,

This is covered in the documentation.  Press F1.

-Boo

Show quoteHide quote
> In VS.2005 using VB.NET
>
> I have tried to make a string
>
> dim abc as string
> abc = format(now,"mm/dd/yyyy")
> or
> abc format$(now,"mm/dd/yyyy")
> but it doesn't work.
>
> I get:  28/25/2006
>
> the day and year are ok, but the month is always wrong, the month is
> something different every time,
>
> Thanks in Advance,
>
> Laurence
>
Author
26 Sep 2006 4:47 AM
Cor Ligthert [MVP]
Laurence,

You are free to use the Format, but did you know that there was the
overloaded ToString with the DateFormatProvider

dim abc as string = now.ToString("d")

I am not sure if it is d but that you can lookup on msdn.

I hope this helps,

Cor

Show quoteHide quote
"Laurence" <Someth***@Something.com> schreef in bericht
news:uAYJPuQ4GHA.3644@TK2MSFTNGP03.phx.gbl...
> In VS.2005 using VB.NET
>
> I have tried to make a string
>
> dim abc as string
> abc = format(now,"mm/dd/yyyy")
> or
> abc format$(now,"mm/dd/yyyy")
>
> but it doesn't work.
>
> I get:  28/25/2006
>
> the day and year are ok, but the month is always wrong,
> the month is something different every time,
>
> Thanks in Advance,
>
> Laurence
Author
26 Sep 2006 6:22 AM
Steven Nagy
Another answer besides those provided:

Dim abc as string = DateTime.Now.ToShortDateString()