Subtracting and Adding Times

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

Guest

I am tracking times, such as; when users clock in and then when they clock out.
I would like to take the difference between the two times. When I subtract
and add the times the minutes and seconds are correct but it adds a 12 for
the hour and then an AM at the end. How can I just record the change in time?
 
12 AM is hour 0. Just change the formatting of the field/control to hh:nn:ss
in table design or form design.

A value that formerly displayed as 12:05:10 AM will then display as 0:05:10
(but the underlying value, which is correct, will not change)

HTH,
 
I am tracking times, such as; when users clock in and then when they
clock out. I would like to take the difference between the two times.
When I subtract and add the times the minutes and seconds are correct
but it adds a 12 for the hour and then an AM at the end. How can I
just record the change in time?

Remember that date values hold fractions of a day, so a little bit of
primary school maths gets this:

Public Sub timediff()
Const dtTimeIn As Date = "12:34"
Const dtTimeOut As Date = "14:44"

Dim dblTimeDiffInDays As Double
Dim intTimeDiffInHours As Integer
Dim intTimeDiffInMinutes As Integer

dblTimeDiffInDays = CDbl(dtTimeOut) - CDbl(dtTimeIn)

intTimeDiffInHours = Int(dblTimeDiffInDays * 24)

intTimeDiffInMinutes = _
dblTimeDiffInDays * 1440 - intTimeDiffInHours * 60

Debug.Print Format(intTimeDiffInHours, "00") & _
":" & _
Format(intTimeDiffInMinutes, "00")


End Sub


Hope that helps


Tim F
 
Back
Top