15 May 2012 at 08:13 #1 Goldy Goldy Associate Joined 30 Mar 2004 Posts 1,148 Location West Wing How do I show the month in the MM format? For example, Code: DateTime now = DateTime.Now; int month = DateTime.Now.Month; This shows the month as 5 but i need it as 05. Thanks!
How do I show the month in the MM format? For example, Code: DateTime now = DateTime.Now; int month = DateTime.Now.Month; This shows the month as 5 but i need it as 05. Thanks!
15 May 2012 at 08:35 #2 GravyMonster GravyMonster Soldato Joined 18 Oct 2002 Posts 16,083 Location The land of milk & beans If you need leading zeroes you need to use a formatted string instead of an int: Code: string month = DateTime.Now.ToString("MM"); // MM = month with leading zero Or Code: string month = DateTime.Now.Month.ToString("00"); Or Code: string month = DateTime.Now.Month.ToString().PadLeft(2, "0");
If you need leading zeroes you need to use a formatted string instead of an int: Code: string month = DateTime.Now.ToString("MM"); // MM = month with leading zero Or Code: string month = DateTime.Now.Month.ToString("00"); Or Code: string month = DateTime.Now.Month.ToString().PadLeft(2, "0");
15 May 2012 at 09:00 #3 Goldy Goldy Associate OP Joined 30 Mar 2004 Posts 1,148 Location West Wing Thanks very much!