Formatting the difference between two dates

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

Guest

Hi, I want to output the results of a '-' operation (finding the difference)
on two general dates. The answer I get is a small decimal value, I assume it
means 0.00976 of a day or something like that. What I'd like to be able to do
is format that differential in terms of Days, hours and minutes etc. Any
ideas?

cheers
 
I found an old, old Microsoft article that talked about a
DaysHoursMinutes(#Time1# - #Time2#) function that would do perfectly except
it was written about ten years ago and I'm using 2002. Does anyone know the
modern syntax for it?
 
Sweet, can you help me a little more tho please. I'm unfamiliar with VB
syntax (I'm a Java guy) and I'm not sure how to set this up properly. I
copied the code to a new module.
In Java I would call the function simply by typing Time_Diff =
Diff2Dates("days", T1, T2) but VB says I can't call a function there. ???

cheers
 
Presumably you pasted the code into a standard module (Modules tab of the
Database window).

Then from the code window, check that it compiles okay: Compile on Debug
menu.

To test it, open the Immediate Window (Ctrl+G), and enter something like:
? Diff2Dates("dhn", #1/1/2003#, Now())

From there you should be able to use it in whatever context you wish. For
example, in a query you could type this into the Field row in query design:
Diff2Dates("dhn", [StartTime], [EndTime])
 
Error: Expected Variable or Procedure, Not a Module.

eep =(

Allen Browne said:
Presumably you pasted the code into a standard module (Modules tab of the
Database window).

Then from the code window, check that it compiles okay: Compile on Debug
menu.

To test it, open the Immediate Window (Ctrl+G), and enter something like:
? Diff2Dates("dhn", #1/1/2003#, Now())

From there you should be able to use it in whatever context you wish. For
example, in a query you could type this into the Field row in query design:
Diff2Dates("dhn", [StartTime], [EndTime])

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

nick said:
Sweet, can you help me a little more tho please. I'm unfamiliar with VB
syntax (I'm a Java guy) and I'm not sure how to set this up properly. I
copied the code to a new module.
In Java I would call the function simply by typing Time_Diff =
Diff2Dates("days", T1, T2) but VB says I can't call a function there. ???

cheers
 
Back
Top