Datetime

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a string with the following structure:
20060227111500 (Year Month day hour minute second)
And I would like to convert it to a datetime variable, but I don't find a
method to do it.

Thanks
 
public DateTime GetDateTimeFromString(string dateString)
{
//Date functions
int year = int.Parse(dateString.Substring(0, 4));
int month = int.Parse(dateString.Substring(4, 2));
int day = int.Parse(dateString.Substring(6, 2));

int hour = int.Parse(dateString.Substring(8, 2));
int minute = int.Parse(dateString.Substring(10,2));
int second = int.Parse(dateString.Substring(12,2));

return new DateTime(year, month, day, hour, minute, second);
}
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Back
Top