2 textbox's converting to a timevalue

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

Guest

Hi!

I have a logical problem. How can I convert 2 textboxvalues,(one for hours
and one for minutes) to a common value type of float or double. I wish to
save this new value in a database

Any help appreciates

--- < Hans > ---
 
I'm not sure if I understand your question correctly, but if you simply want to
store a single value in the database, why not store it in units of minutes?

You can convert the text in the hours box into minutes, and then add the value
from the minutes box to obtain the overall value.

int hours = int.Parse(hoursTextBox.Text);
int minutes = int.Parse(minutesTextBox.Text);

int totalMinutes = (hours * 60) + minutes;

For something like this, you could use ints instead of doubles (assuming you
don't have to deal with fractional hours/minutes.)

To recreate the values you simply do this:

int hours = totalMinutes / 60;
int minutes = totalMinutes % 60;

If the two textbox values can contain any number of hours and minutes, like 546
hours and 345 minutes, you might want to store the two values separately to be
able to get the original values back.

Hope this helps.
 
Back
Top