Time between Two Dates

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

Guest

I got a problem that calculates the totoal time from when a issue was entered
in a database and the time it was answered. For example, when the issue start
in Feb 02, 05 and is answered on Feb 10, 05, you'll get the correct number.
When the issue cross months, starting in June and ending in July for example,
I get a negative number. How can I fix or stop that from happening?
 
What is the equation you're using to do the calculation? Have you tried the
DateDiff() function or are you just subtracting the day part of the date
(i.e. in the example you gave, just using 10 - 2)?
 
I'm using the Day() and Hour() function.
((((Day([ClosingDate])-Day([OpeningDate]))*24)+(Hour([ClosingTime])-Hour([OpeningTime])))
 
Ok, by using the Day() function, you are just subtracting the day part (i.e.
10 - 2). You have done nothing to take into consideration the month or year.
It appears that you want the result in hours. Try the example below.

Example:
Dim dteClosing As Date, dteOpening As Date
Dim lngHoursDifference As Long
'First, let's get the entire date and time together
dteClosing = [ClosingDate] + [ClosingTime]
dteOpening = [OpeningDate] + [OpeningTime]
lngHoursDifference = DateDiff("h", dteOpening, dteClosing)

--
Wayne Morgan
MS Access MVP


Greg2582 said:
I'm using the Day() and Hour() function.
((((Day([ClosingDate])-Day([OpeningDate]))*24)+(Hour([ClosingTime])-Hour([OpeningTime])))

Wayne Morgan said:
What is the equation you're using to do the calculation? Have you tried
the
DateDiff() function or are you just subtracting the day part of the date
(i.e. in the example you gave, just using 10 - 2)?
 
Back
Top