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!

computing difference between 2 times

Status
Not open for further replies.

peglin

IS-IT--Management
Jul 12, 2002
14
US
Hi. how do I compute the difference between two times? In the result, I want to see the hour difference and minute difference as HH:MM, not just the hour or minute. the time1 and time2 are formatted 'YYYY-MM-DD HH:MM:mm.ss'. I only want the HH:MM part from the computed difference. Thank you.
 
Try the SecondsAfter function, it gets the number of seconds one time occurs after another. Syntax :

SecondsAfter ( time1, time2 )

Then just devide by 60 for minutes and 60 again for hours... hope this helps
 
Hi,

Your solution to your problem is to use the SecondsAfter() function. It returns a long value of seconds being the difference between the two time values. To conver this value to a time format, just use the String() function to format the computation:

//////////////////////////////////////////////////////////
time lt_Time1, lt_Time2 ;
long ll_Secs ;
string ls_Diff ;
//
ll_Secs = SecondsAfter( lt_Time1, lt_Time2 ) ;
//
ls_Diff = String(( ll_Secs / 60 ) / 60 ) + ":" + String( ll_Secs / 60 )
//////////////////////////////////////////////////////////

Hope this helps...

--
PowerObject!
-----------------------------------------
PowerBuilder/PFC Developers' Group
 
Hi Peglin,

I hate to offer any code that is not from a real-world situation. The above code I posted yesterday does have some glitches. However, you have posted the same question onto another group and I posted a bug-free solution out there. Just surf to:

[a href="[URL unfurl="true"]http://groups.yahoo.com/group/PowerObject/message/355"[/URL]][/a]

Regards,

--
PowerObject!
 
Thank you for your help. I'll try that out. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top