Convert date yyyyMMdd to system.datetime format [duplicate]
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;
string time = "19851231";
DateTime theTime= DateTime.ParseExact(time,
"yyyyMMdd",
CultureInfo.InvariantCulture,
DateTimeStyles.None);
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