tags:

views:

62

answers:

3

DUP: http://stackoverflow.com/questions/501460/format-date-in-c

I have a datetime object (initialized), how can I output the month part as MM?

+8  A: 

Your_Date_Time_Object.ToString("MM")

emaster70
You beat me to it. +1 for doing it in one line.
Lucas McCoy
A: 
DateTime date = DateTime.Now;              // Use current date
string format = "MM";                      // Use this format
Console.WriteLine(date.ToString(format));  // Write to console
Lucas McCoy
+1  A: 

Similar questions exist:

http://stackoverflow.com/questions/501460/format-date-in-c

There's a useful link with a plenitude of examples in one of the answers of the above question as well.

Jagd