How do I get today's date in C# in mm/dd/yyyy format?

DateTime.Now.ToString("M/d/yyyy");

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx


Not to be horribly pedantic, but if you are internationalising the code it might be more useful to have the facility to get the short date for a given culture, e.g.:-

using System.Globalization;
using System.Threading;

...

var currentCulture = Thread.CurrentThread.CurrentCulture;
try {
  Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-us");
  string shortDateString = DateTime.Now.ToShortDateString();
  // Do something with shortDateString...
} finally {
  Thread.CurrentThread.CurrentCulture = currentCulture;
}

Though clearly the "m/dd/yyyy" approach is considerably neater!!


DateTime.Now.ToString("dd/MM/yyyy");

Tags:

C#

Date