I have a datetime object (initialized), how can I output the month part as MM?
Asked
Active
Viewed 122 times
2 Answers
8
Your_Date_Time_Object.ToString("MM")
Tim Cooper
- 151,519
- 37
- 317
- 271
em70
- 6,058
- 5
- 46
- 80
-
You beat me to it. +1 for doing it in one line. – Kredns May 04 '09 at 21:50
0
DateTime date = DateTime.Now; // Use current date
string format = "MM"; // Use this format
Console.WriteLine(date.ToString(format)); // Write to console
Kredns
- 35,368
- 50
- 149
- 201