Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

subtract dates for duration

Status
Not open for further replies.

MARTINRODDY

Programmer
Apr 3, 2001
30
US
Hi there,

I am trying to subtract 2 date and time fields to work out a duration in a state; For example:

end time start time
(26/11/2001 16:22:00) -(26/11/2001 16:00:00)

duration here will = 00:20:00 in hh:mm:ss format.

How can I do this, any help is much appreciated.

Thank you
Martin.
 
Use the datediff fiunction. The syntax is:

DateDiff(IntervalType,StartDateTime,EndDateTime)

If you need to get days, hours, minutes and seconds, you would need to use 4 formulas:

Days->DateDiff("d",StartDT,EndDT)

Hours->DateDiff("h",StartDT,EndDT)

Minutes->DateDiff("n",StartDT,EndDT) yes 'n'. 'm' is reserved for months

Seconds->DateDiff("s",StartDT,EndDT)

I've never tried to piece all of these together in one formula but I am sure it could be done. In fact the idea of a "Duration" function, with an argument(s) for how detailed it needs to be (down to minutes, seconds, etc) is a great idea for a user defined function.

Software Support for Sage Mas90, Macola, Crystal Reports and Goldmine
 
if you convert the difference to seconds, you can use a formula I wrote to create your time string. See my FAQ on common formulas ( faq149-243 ) for a description. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top