Convert Now to a string

  • Thread starter Thread starter Laurence
  • Start date Start date
L

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
 
Laurence said:
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.
 
Use MM for month with leading zero.
mm is minute with leading zero.
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



--
 
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
 
Another answer besides those provided:

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