Odd date.tostring problem

M

MartinTeefy

Hi,

I need to write todays date incremented by one month as part of a string for
a licence but i'm getting odd results as the tostring function is extracting
the middle data section of the datetime variable:

Dim dTrialExpiryDate As DateTime = DateTime.Now.AddMonths(1)

This give the value 13/07/2008 13:52:05

I now want to change this value to 07/13/2008

sTrialExpiryString = dTrialExpiryDate.ToString("mm/dd/yyyy")

but the string contains 52/13/2008 i.e. it takes the 2008 13:52 from the
middle section of the datetime variable???

Any ideas
Thanks
 
M

MartinTeefy

I thought i'd fixed it but no

I changed the declaration to

Dim dTrialExpiryDate As Date = Date.Now.AddMonths(1)

This gives 13/07/2008 14:02:46 (i expected 13/07/2008) and the tostring call
gives 02/13/2008

Now i'm really confused...
 
C

Chris Dunaway

Your format string is incorrect. You are using ToString("mm/dd/yyyy")
when you should be using ToString("MM/dd/yyyy"). Lower case mm gives
you minutes, while upper case MM gives you the month.

Chris
 
G

Göran Andersson

MartinTeefy said:
Hi,

I need to write todays date incremented by one month as part of a string for
a licence but i'm getting odd results as the tostring function is extracting
the middle data section of the datetime variable:

Dim dTrialExpiryDate As DateTime = DateTime.Now.AddMonths(1)

This give the value 13/07/2008 13:52:05

I now want to change this value to 07/13/2008

sTrialExpiryString = dTrialExpiryDate.ToString("mm/dd/yyyy")

but the string contains 52/13/2008 i.e. it takes the 2008 13:52 from the
middle section of the datetime variable???

Any ideas
Thanks

That's not odd at all. The "mm" part of the format string doesn't stand
for months, it stands for minutes.

Use "MM/dd/yyyy".
 
C

Cor Ligthert[MVP]

Hi Martin,

Some people gives us always a smile, but don't bother, I think we all have
gone once in this trap.

:)

Cor
 

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