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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying a time as HH:MM:SS or DD:HH:MM:SS

Formula Help

Displaying a time as HH:MM:SS or DD:HH:MM:SS

by  synapsevampire  Posted    (Edited  )
The following formula will return the difference between 2 dates in HH:MM:SS. It is easily modified to return the HH:MM:SS for a seconds field by replacing the dur value with your seconds field/formula.

whileprintingrecords;
numberVar dur := datediff("s",{Orders.Order Date}, currentdate); //get the seconds between 2 dates
numberVar hrs;
numberVar min;
numberVar sec;
stringVar hhmmss;

hrs := Truncate(Truncate(dur/60)/60);
min := Remainder(Truncate(dur/60),60);
sec := Remainder(dur,60);

hhmmss := totext(hrs,"00") + ":" + totext(min,"00") + ":" + totext(sec,"00");

hhmmss


To include days, use:

whileprintingrecords;
numberVar dur := datediff("s",{Orders.Order Date}, currentdate); //get the seconds between 2 dates
numbervar days;
numberVar hrs;
numberVar min;
numberVar sec;
stringVar ddhhmmss;
days:= Truncate(Truncate(Truncate(dur/60)/60)/24);
hrs := Remainder(Truncate(Truncate(dur/60)/60),24);
min := Remainder(Truncate(dur/60),60);
sec := Remainder(dur,60);

ddhhmmss := totext(days,0,"") + ":" + totext(hrs,"00") + ":" + totext(min,"00") + ":" + totext(sec,"00");

ddhhmmss
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top