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

Recommended Answers

All 6 Replies

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);

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.

You can use DateTime.TryParse() for this purpose: (examples at the end of link)
http://msdn.microsoft.com/en-us/library/ch92fbc1.aspx
http://msdn.microsoft.com/en-us/library/9h21f14e.aspx

Thanks All .

the code worked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.