i have 3 text boxes a b and c

i would like to enter time into the a and b and have c calculate the tot time in hrs and minutes between those two.

Sounds easy, what part specifically are you having trouble with? You need to try and make an effort first, don't expect anyone to do all the work for you.

How would you enter time in a textbox? Which format would you use? How would you validate the input of the user?
I would consider a DateTimePicker control for that.

sure it is easy if you know it
..... i am trying to learn it

i thought there is a way to use the TimeDiff function to calculate the difference

any ides?

How would you enter time in a textbox? Which format would you use? How would you validate the input of the user?
I would consider a DateTimePicker control for that.

would like to input it into a text box
like

txtboxa 12:45
txtboxb 5:15

and get the diff...

i looked at the date time picker but i dont want the date in that field
is there a way to cut the day out and just use the time?

Use a custom format:
Like so :

dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "HH:mm";
HH meaning 24 hour with 2 digits
mm meaning the minutes.

You can convert hh:mm:ss to a date, check it's valid and get the difference between times

Dim TimeA As Date
Dim TimeB As Date
Dim hh As Integer
Dim mm As Integer
Dim ss As Integer

If Not Date.TryParse(TextBox1.Text, TimeA) Then
  ' Not a date
End If
If Not Date.TryParse(TextBox2.Text, TimeB) Then
  ' Not a date
End If
' Subtract (= time between)
hh = TimeB.Subtract(TimeA).Hours
mm = TimeB.Subtract(TimeA).Minutes
ss = TimeB.Subtract(TimeA).Seconds
TextBox3.Text = hh.ToString.PadLeft(2, CChar("0")) & ":" & mm.ToString.PadLeft(2, CChar("0")) & ":" & ss.ToString.PadLeft(2, CChar("0"))

I cutomized the datetimepicker
TIMEINTextBox.Format = DateTimePickerFormat.Custom
TIMEINTextBox.CustomFormat = "HH:mm"

And now when i put values into the field, it wont save to the database.


To write to the database I have the generic

Me.Validate()
Me.REPORTBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.REPORT)

Did you get your original question

Time difference between two text boxes

solved? If yes, then mark the thread as solved.

Start a new thread for "how to save customized time format to a db". In that thread, tell which db you're using and show a bit more code i.e. what is your customized date/time format and how you try to save customized date/time format to db.

Nice code.
How can i get the sum of all the times from Monday to Sunday
and calculate the overtime if totalHours >= 40 there is overtime
otherwise overtime is =0
Thanks

This article has been dead for over six months. Start a new discussion instead.