Odd date.tostring problem

  • Thread starter Thread starter MartinTeefy
  • Start date Start date
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
 
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...
 
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
 
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".
 
Hi Martin,

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

:-)

Cor
 
Back
Top