in C# I’m trying to do a DateTime.TryParse on a string field which I am getting from a DataFeed which I know is in “MM/dd/YYYY” format. e.g.
DateTime dt = DateTime.TryParse("01/30/11");
Only thing is now “dt” is in the incorrect format to be stored into my Database which has a DateTime locale setting of “dd/MM/YYYY”.
How do I go about parsing the string field correctly into dt and then into my DB? What would be the best way to handle this? If I set the globalization of my CurrentThread to en-US, then dt would be in en-US format, however when inserting into the DB, it is still incorrectly stored? :S
Thanks
David
Use the DateTime.ParseExact method:
If you want to convert the DateTime value to a string back, use the following code: