Friday, February 10, 2012

C# convert string to DateTime structure

So, you need to convert a string do DateTime structure, i.e. string from Database. The key is to save the string in an extensive format which includes years, months, days, hours, minutes and seconds, for example: "dddd, MMMM d, yyyy hh:mm:ss" which displays as "Friday, February 10, 2012, 12:04:14"
This way the DateTime structure will contain the commonly used time parameters for further processing.

using System;

string my_time = "Friday, February 10, 2012, 12:04:14"
DateTime reminder_date_time = DateTime.Parse(my_time);

No comments:

Post a Comment