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


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

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