[Solved] how to convert label.text= dr[“column’].tostring to datetime?


You need to know the Format in which user inputs the Date Value

For example if the format i dd-MM-yyyy

Try This:

DateTime dt = DateTime.ParseExact(lbltimein.Text,"dd-MM-yyyy",
       System.Globalization.CultureInfo.InvariantCulture) ;

EDIT: from the comments if you have the time in format of HH:mm:ss
You can Split it based on semicolon and assign it to TimeSpan constructor to get the total hours.

var time = lbltimein.Text.Split(':');
TimeSpan time=new TimeSpan(Convert.ToInt32(time[0]),
                             Convert.ToInt32(time[1]),Convert.ToInt32(time[2]));
double totalHours = time.TotalHours;

EDIT 2: if you have format like : 08:00:00 AM

Try This:

var inputtime = lbltimein.Text;
TimeSpan time = new TimeSpan(Convert.ToInt32(inputtime.Substring(0,2)),
                            Convert.ToInt32(inputtime.Substring(3, 2)), 
                            Convert.ToInt32(inputtime.Substring(6, 2)));
double totalHours = time.TotalHours;

8

solved how to convert label.text= dr[“column’].tostring to datetime?