How to get DateTime month in upper case?

18,820

Solution 1

Just do the string ToUpper():

    DateTime CusDate = dateTimePicker1.Value;
    string Date = CusDate.ToString("ddMMMyyyy").ToUpper();

Solution 2

After you're done with the toString...

string date = date.ToUpper();

Solution 3

Use the String.ToUpper() method:

DateTime CusDate = dateTimePicker1.Value;
string Date = CusDate.ToString("ddMMMyyyy").ToUpper();

Solution 4

Convert the string to upper case (won't affect the numbers):

DateTime CusDate = dateTimePicker1.Value;
string Date = CusDate.ToString("ddMMMyyyy").ToUpper();
Share:
18,820
Sharrok G
Author by

Sharrok G

Updated on July 27, 2022

Comments

  • Sharrok G
    Sharrok G almost 2 years

    I am using the following to format a DateTime:

    DateTime CusDate = dateTimePicker1.Value;
    string Date = CusDate.ToString("ddMMMyyyy");
    

    I am getting the format such that "Nov" is not in upper case:

    04Nov2011
    

    But I want the format of "Nov" in capital letters, like this:

    04NOV2011
    

    This is because I am downloading a file from a website programatically which is in this format.

  • Tim
    Tim over 12 years
    Simpler to add the .ToUpper() call after the .ToString("ddMMMyyyy") call, I think. Not sure if there's any actual under-the-hood differences though.
  • Haedrian
    Haedrian over 12 years
    The compiler will probably optimise it anyway.
  • Tim
    Tim over 12 years
    True enough. Might be interesting to compare the MSIL between the two, but for all intents and purposes it's fine either way.