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

Keng picture Keng · Aug 28, 2008 · Viewed 350.2k times · Source

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

I need to set a string variable to today's date (preferably without the year), but there's got to be a better way than building it month-/-day one piece at a time.

BTW: I'm in the US so M/dd would be correct, e.g. September 11th is 9/11.

Note: an answer from kronoz came in that discussed internationalization, and I thought it was awesome enough to mention since I can't make it an 'accepted' answer as well.

kronoz's answer

Answer

Joel Coehoorn picture Joel Coehoorn · Aug 28, 2008
DateTime.Now.ToString("M/d/yyyy");

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