Convert Dec06 to Dec 2006

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

I can't seem to get this to work. Everything I try always seems to convert
it to Dec 06 2005.

I tried using DateTimeFormatInfo and setting YearMonth = "MMYY"
and then doing DateTime.Parse(mydate, cultureinfo)
 
Joe said:
I can't seem to get this to work. Everything I try always seems to
convert it to Dec 06 2005.

I tried using DateTimeFormatInfo and setting YearMonth = "MMYY"
and then doing DateTime.Parse(mydate, cultureinfo)

I suppose the issue is that it's not a complete date without the day
portion. Any parsing routine would have to make a guess at what you
want for the day i.e. start of month or end of month.

Cheers Tim.
 
Joe said:
I can't seem to get this to work. Everything I try always seems to convert
it to Dec 06 2005.

So then just take the .Month and .Year properties and add them together.
 
Joe said:
I can't seem to get this to work. Everything I try always seems to convert
it to Dec 06 2005.

I tried using DateTimeFormatInfo and setting YearMonth = "MMYY"
and then doing DateTime.Parse(mydate, cultureinfo)

Use DateTime.ParseExact (myDate, "MMMyy", cultureInfo);

where cultureInfo is the relevant culture (or null to use the current
culture). You don't need to change anything in any actual cultures.

The real problem was that your format specifier was wrong though - you
need MMM for text, rather than MM (which would expect 01-12).
 
Back
Top