0

Possible Duplicate:
Convert dd-mm-yyyy into mm/dd/yyyyy in C#

I want to Convert Date time format from dd/MM/yyyy to MM/dd/yyyy in C#

Is there any suggestion how to do that?

Community
  • 1
  • 1
amee
  • 11
  • 1
  • 1
  • 1

3 Answers3

2

Please try:

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
1
DateTimeFormatInfo usDtfi = new CultureInfo("en-US", false).DateTimeFormat; //--MM/dd/yyyy
DateTimeFormatInfo ukDtfi = new CultureInfo("en-GB", false).DateTimeFormat; //--dd/MM/yyyy
DateTime result = Convert.ToDateTime("07/21/2011", usDtfi); //or: ("21/07/2011", ukDtfi)

Then you have a DateTime Object (result) and do whatever you want like:

string str = result.ToString("yyyy-MM-dd HH:mm:ss");

Happy Coding :)

Kent
  • 2,952
  • 2
  • 25
  • 42
1

try this

string DateString  = "22/04/2011";
DateTime date = new DateTime();
date = DateTime.ParseExact(DateString, "dd/MM/yyyy");
string NewDateString = date.ToString("MM/dd/yyyy");
Yassine Zaroui
  • 403
  • 3
  • 14