Hi
i need to convert date format 16/1/2010 10:10:2011 AM to 1/16/2010 10:10:2011 AM after that i need to put values to database too as datetime datatype.Can you please help.


many thanks in advance

This is how you can convert into both cases:

string ss2 = DateTime.Now.ToString("dd/MM/yyyy hh:mm.ss tt", System.Globalization.CultureInfo.InvariantCulture);
 string ss3 = DateTime.Now.ToString("MM/dd/yyyy hh:mm.ss tt", System.Globalization.CultureInfo.InvariantCulture);

This is how you can convert into both cases:

string ss2 = DateTime.Now.ToString("dd/MM/yyyy hh:mm.ss tt", System.Globalization.CultureInfo.InvariantCulture);
 string ss3 = DateTime.Now.ToString("MM/dd/yyyy hh:mm.ss tt", System.Globalization.CultureInfo.InvariantCulture);

Hi,

many thanks for the reply

but my issue is server time is in UK standard , it displays time as "MM/dd/yyyy hh:mm.ss tt" format. i saved this value into string.and converted it to "dd/MM/yyyy hh:mm.ss tt" format.then i cant convert this string value back to datetime datatype.

Try this conversation:

DateTime dDate = DateTime.Now;
string sDate = dDate.ToString("dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-GB"); //dd/MM/yyyy
DateTime newDate = DateTime.Parse(sDate);

Edited 5 Years Ago by Mitja Bonca: n/a

This question has already been answered. Start a new discussion instead.