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

Posted on 2012-09-09
Last Modified: 2012-09-09
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.


string[] lines = { "CODEPAGE:850",
                                   "COMMENT:--------------Xcel Report load-------------------",
                                   "GROUP_FIELD_VALUE:" + REPTYR,
                                   "GROUP_FIELD_VALUE:" + DateTime.Now.ToString("mm/dd/yyyy"),
                                   "GROUP_FILENAME:/clientdoc/" + strFile4 };  
                System.IO.File.WriteAllLines(strFile2, lines);
Question by:zimmer9
    1 Comment
    LVL 74

    Accepted Solution

    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:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now