Aluedke
asked on
Convert/Parse string to Timespan
I have a text box (txtTime) that retrieves a user inputted value as time (ex. 3:00 PM). I have a field (StartTime) in my database of type time(7) to store this value in.
Unfortunately, I'm unable to convert the string from the textbox to this timespan value. Any help would be appreciated.
txtTime.Text is equal to 3:00 PM (the time can change), but the following doesn't work.
Timespan Time = Timespan.Parse(txtTime.Tex t);
Unfortunately, I'm unable to convert the string from the textbox to this timespan value. Any help would be appreciated.
txtTime.Text is equal to 3:00 PM (the time can change), but the following doesn't work.
Timespan Time = Timespan.Parse(txtTime.Tex
a timespan is an interval of time or the time since midnight so 3:00pm doesn't qualify perhaps convert to datetime instead
How about this?
DateTime.Parse("03:00 PM").TimeOfDay
TimeOfDay is of type TimeSpan
DateTime.Parse("03:00 PM").TimeOfDay
TimeOfDay is of type TimeSpan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I had the same issue. However, elkhawajah's answer is the one that worked for me. I use VS 2008 and SS 2008 which allows storing as a Time type. When I tried cmrobertson's solution, it would not convert a string to a Timespan. However, when I used the following, it worked fine.
Dim tsTime as Timespan = DateTime.Parse(txtTime.Tex t).TimeOfD ay
Just wanted to add the comment for anyone else seeking an answer to storing to the Time type in SS 08.
Dim tsTime as Timespan = DateTime.Parse(txtTime.Tex
Just wanted to add the comment for anyone else seeking an answer to storing to the Time type in SS 08.