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

How to keep the result in HH:MM:SS when doing subtraction

Status
Not open for further replies.

EngJoo

Programmer
Joined
May 14, 2002
Messages
90
Location
MY
Dear all,

i would like to know the formula for keep the result in HH:MM:SS when i am doing the subtraction between 2 different time.

please advice.

 
You need to convert ToSeconds when subtracting.

When you have your ToSeconds total, reconvert it using the following:
Code:
WhilePrintingRecords; 
NumberVar SecondsTotal := {YourSecondsTotalField}; 
NumberVar MyHour := Truncate(Remainder(SecondsTotal,86400)/3600); 
NumberVar MyMinute := Truncate(Remainder(SecondsTotal,3600)/60); 
NumberVar MySecond := Remainder(SecondsTotal,60); 

ToText(MyHour,'00',0,"")+':'+ToText(MyMinute,'00',0,"")+':'+ToText(MySecond,'00',0,"");
Naith
 
why not just this:
TimeValue({Date1} - {date2)

 
You're very probably right, Kataka. But I can only get the TimeValue to return accurately when used in conjunction with DateTime fields, rather than Time fields.

That said, if the fields here are DateTime fields, then yours is hands down the better option.

Naith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top