Convert Now to a string

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
 
G

Greg

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.
 
W

wilson

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



--
 
C

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
 
S

Steven Nagy

Another answer besides those provided:

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top