dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: PowerBuilder
Expertise: Beginner
Mar 13, 1998

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Adding/Subtracting Time

Question:
How do I add/subtract a series of time values of format hh:mm:ss (for example, 02:45:32 + 00:35:43 + and so on)?

Also, how do I set the mm:ss format?

Answer:
You can use the RelativeTime function to add and subtract seconds from a time variable. To add minutes and hours, you need to use the minutes and hour function to extract the value and multiply it up to be a seconds value.

To convert a time variable into a string time in the format mm:ss, use the second form of the string function that allows you to specify an edit mask:

ls_Time = String( Now(), 'mm:ss' )
But what if the time goes past midnight?

To solve this problem, calculate the number of seconds between the old time and midnight and then see whether this number of seconds is greater than the number of seconds you want to add to your time.

If it is, use the RelativeDate function to add a day to the date and then subtract the number of seconds between the old time and midnight from the number of seconds you want to add, and then add those number of seconds to midnight.

If you need to work for more than 24 hours, put this in a loop until you have reduced the number of seconds to a number small enough not to roll past midnight.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date