Click here to Skip to main content
15,886,840 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i am having a problem converting a string with different culture to datetime.

I want to convert any format (any culture) to datetime

"Ср, 01.08.2014" Russian format

Please help me to solve this.
Posted
Comments
dan!sh 7-Jan-14 1:05am    
Have you had a look at DateTime.TryParseExact yet?
Karthik_Mahalingam 7-Jan-14 1:10am    
as d@nish said, DateTime.PraseExact is enough for conversion in any format.

try this.

C#
string datestr  = "01.08.2014";
        string format = "MM.dd.yyyy";
        DateTime dt = DateTime.ParseExact(datestr, format, System.Globalization.CultureInfo.InvariantCulture);
 
Share this answer
 
Comments
hari111r 7-Jan-14 1:26am    
Hi karthik thanks, its working for me using below

DateTime dt = DateTime.ParseExact("Ср, 01.08.2014", "ddd, MM/dd/yyyy", Thread.CurrentThread.CurrentCulture);

Is the above will support any timezone??
Karthik_Mahalingam 7-Jan-14 1:42am    
DateTime dt = DateTime.ParseExact("Ср, 01.08.2014", "ddd, MM/dd/yyyy", Thread.CurrentThread.CurrentCulture);
this line of code is working ??
i am getting string format exception....
hari111r 7-Jan-14 1:58am    
I have russian in my region and language settings
Karthik_Mahalingam 7-Jan-14 2:07am    
ok. the above set of code not working in for indian region :(
Hi,

Try with this:
private static DateTime? ParseDate(string input)
{
DateTime result;
if (DateTime.TryParseExact(input, formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out result))
{
return result;
}
return null;
}



Regards,
Shree M.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900