DateTime.Now.ToShortDateString(); replace month and day

cnd picture cnd · Feb 2, 2010 · Viewed 108k times · Source

I need to change format of

this.TextBox3.Text = DateTime.Now.ToShortDateString();

so it returns (for example) 25.02.2012, but I need 02.25.2012

How can this be done?

Answer

jason picture jason · Feb 2, 2010

Use DateTime.ToString with the specified format MM.dd.yyyy:

this.TextBox3.Text = DateTime.Now.ToString("MM.dd.yyyy");

Here, MM means the month from 01 to 12, dd means the day from 01 to 31 and yyyy means the year as a four-digit number.