Datetime

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
 
G

Guest

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!
***************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

DateTime Equals method & Ticks 11
Excel Convert Datetime Stamp to HH and MM Worked 7
Dates & calendars 8
UTC to DateTime 5
TimeSpace.Parse() usage 3
DateTime 2
TimeSpan inadequacies 3
using DateTime in a for/next loop 1

Top