Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


computing difference between 2 times

computing difference between 2 times

computing difference between 2 times

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.

RE: computing difference between 2 times

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

RE: computing difference between 2 times


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...

PowerBuilder/PFC Developers' Group

RE: computing difference between 2 times

Thank you for your help. I'll try that out. Thanks again.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close