I have date in format \"MM/DD/YYYY\" e.g. \"09/25/2011\", how i can convert this in format \"DD/MM/YYYY\".
my code is:
private DateTime GetDate()
{
Have you tried formatting the date
object as dd/MM/yyyy
?
string d = Convert.ToDateTime("09/25/2011").ToString("dd/MM/yyyy"); //returns 25/09/2011
DateTime date = DateTime.Parse("09/25/2011", new CultureInfo("en-GB")); // returns 09/25/2011
string d2 = date.ToString("dd/MM/yyyy"); //should return 25/09/2011
string input = Console.ReadLine();
string[] dtarray = input.Split('/');
DateTime datechanged = new DateTime(Convert.ToInt32(dtarray[2]),Convert.ToInt32(dtarray[1]),Convert.ToInt32(dtarray[0]));
I would suggest your function just does the following...
private DateTime GetDate()
{
return DateTime.ParseExact("09/25/2011", "MM/dd/yyyy", null);
}
Then when you use the function...
string formattedDate = GetDate().ToString("dd/MM/yyyy");