How do I format DateTime as mmddyyyy

  • Thread starter Thread starter Jack
  • Start date Start date
J

Jack

I am trying to format a DateTime object as mmddyyyy and NOT mm/dd/yyyy. What
is the easiest way to do this?
 
Use the ToString overload and pass the format required in it.

Eg:
dt.ToString("mmddyyyy"); or
dt.ToString("dd-mm-yy");
 
That is what I was attempting but found a nuance... mmddyyyy formats as
minute, day, month. The correct format is MMddyyyy.
 
Jack said:
I am trying to format a DateTime object as mmddyyyy and NOT mm/dd/yyyy. What
is the easiest way to do this?
DateTime dt = DateTime.Now;

System.Console.WriteLine(string.Format("{0,2:00}{1,2:00}{2,04:0000}",dt.Day,dt.Month,dt.Year));
 
anon said:
DateTime dt = DateTime.Now;

System.Console.WriteLine(string.Format("{0,2:00}{1,2:00}{2,04:0000}",dt.Day,dt.Month,dt.Year));

or alternatvely:

dt.ToString("MMddyyyy");

/J\
 
Back
Top