0

I want to convert date DD-MM-YYYY into default format of date time "MM/DD/YYYY" in C#.

is there string format which helps me to do.

skaffman
  • 398,947
  • 96
  • 818
  • 769
amee
  • 1
  • 1
  • 1

3 Answers3

4
(DateTime.ParseExact(input, "dd-MM-yyyy", CultureInfo.InvarientCulture).ToString("MM/dd/yyyy")

(Not assuming any defaults – "mm/dd/yyyy" is not the default date format for most people.)

Richard
  • 106,783
  • 21
  • 203
  • 265
-1

Try This

DateTime dt = GetDate(DateStringToConvert); 
dt.ToString("MM/dd/yyyy");
Fahad Hussain
  • 1,165
  • 1
  • 10
  • 17
  • There is no GetDate(string) API in the C# System package. What method are you attempting to invoke? – Clayton Jul 21 '11 at 23:41
  • DateTime.Parse(string) would be the closest match to the "GetDate" method, I'm guessing. In this case, I would recommend the TryParse() method though, just to protect against malformed input. – fatty Jul 22 '11 at 04:44
-1
string oldstr = "03/12/2011";   
string strDate = DateTime.ParseExact(oldstr, "dd/MM/yyyy",null).ToString("MM/dd/yyyy");
Console.WriteLine(strDate);
Monday
  • 1,403
  • 12
  • 10