Why does the month come out as 59 using the following C# code?

I am developing a C# application on a Windows platorm using VS2005.

Why does the month come out as 59 (59/09/2012) using the following C# code?

I copy the following statements into a file represented by variable strFile2 and in the file
the following values are generated.

GROUP_FIELD_NAME:ReportDate
GROUP_FIELD_VALUE:59/09/2012
-------------------------------------------------------------------------------------------

string[] lines = { "CODEPAGE:850",
                                   "COMMENT:--------------Xcel Report load-------------------",
                                   "GROUP_FIELD_NAME:REPTID",
                                   "GROUP_FIELD_VALUE:METRICS",
                                   "GROUP_FIELD_NAME:REPTYR",
                                   "GROUP_FIELD_VALUE:" + REPTYR,
                                   "GROUP_FIELD_NAME:ReportDate",
                                   "GROUP_FIELD_VALUE:" + DateTime.Now.ToString("mm/dd/yyyy"),
                                   "GROUP_OFFSET:0",
                                   "GROUP_LENGTH:0",
                                   "GROUP_FILENAME:/clientdoc/" + strFile4 };  
   
 
                System.IO.File.WriteAllLines(strFile2, lines);
zimmer9Asked:
Who is Participating?
 
käµfm³d 👽Commented:
Because "mm" (lowercase) in format strings is minutes (as in time). For months, you need to use uppercase letters:

...
"GROUP_FIELD_VALUE:" + DateTime.Now.ToString("MM/dd/yyyy"),
...

Open in new window


For a listing of format specifiers, see:  http://blog.stevex.net/string-formatting-in-csharp/
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.