I have string say "12/1/2011" in English US culture my current machine culture is English Uk which is "dd/mm/yyyy" format. How to convert the 12/1/2011 to 1/12/2011. I have tried the below format.
System.DateTime.Parse(result,System.Threading.Thread.CurrentThread.CurrentCulture) .ToString(System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern)
but i could not able to see any output.
-Lokesh.
To convert a datetime to a date, you can use the CONVERT() , TRY_CONVERT() , or CAST() function.
To convert Python datetime to string, use the strftime() function. The strftime() method is a built-in Python method that returns the string representing date and time using date, time, or datetime object.
DateTimeFormatInfo usDtfi = new CultureInfo("en-US", false).DateTimeFormat; DateTimeFormatInfo ukDtfi = new CultureInfo("en-GB", false).DateTimeFormat; string result = Convert.ToDateTime("12/01/2011", usDtfi).ToString(ukDtfi.ShortDatePattern);
This will do the trick ^^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With