Convert date yyyyMMdd to system.datetime format

C#Datetime

C# Problem Overview


> Possible Duplicate:
> how to convert date from yyyyMMdd format to mm-dd-yyyy fomrat

I have a string which contains date in yyyyMMdd format. I want to convert that date into system date format using ConvertTo.DateTime() method or any other simple method.

string value = "19851231";  //yyyyMMdd

DateTime dateTime = 1985/12/31;

C# Solutions


Solution 1 - C#

string time = "19851231";
DateTime theTime= DateTime.ParseExact(time,
                                        "yyyyMMdd",
                                        CultureInfo.InvariantCulture,
                                        DateTimeStyles.None);

Solution 2 - C#

have at look at the static methods DateTime.Parse() and DateTime.TryParse(). They will allow you to pass in your date string and a format string, and get a DateTime object in return.

http://msdn.microsoft.com/en-us/library/6fw7727c.aspx

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPramodChoudhariView Question on Stackoverflow
Solution 1 - C#BrokenGlassView Answer on Stackoverflow
Solution 2 - C#Alastair PittsView Answer on Stackoverflow