string to date - in C# [ "Mon Jan 13 2014 00:00:00 GMT+0000 (GMT Standard Time)"]
c#, date-format, datetime
Solution
You're going to need to use `DateTime.ParseExact`:
var date = DateTime.ParseExact(
"Mon Jan 13 2014 00:00:00 GMT+0000 (GMT Standard Time)",
"ddd MMM dd yyyy HH:mm:ss 'GMT'K '(GMT Standard Time)'",
CultureInfo.InvariantCulture);
after parsing the date you can then send it out your way:
date.ToString("yyyy-MM-dd");
Here's an Ideone to prove it.
Problem
I have a situation in which I am receiving date as a string in following format. "Mon Jan 13 2014 00:00:00 GMT+0000 (GMT Standard Time)" I need to convert it to following format in c# (Either date/string) for further processing `YYYY-MM-DD (2014-01-13)` ``` Convert.ToDateTime(SelectedData) ``` Above code thorws following error: ``` 'Convert.ToDateTime(SelectedData)' threw an exception of type 'System.FormatException' System.DateTime {System.FormatException} ``` Any suggestions? I can't change the format in which I am receiving the date Best Regards.