Convert date yyyyMMdd to system.datetime format
C#DatetimeC# 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.