how to (add,minus,divide) time?

jagr

Member
hi, i want to do some simple calculation for work/rest shift
how do I capure time in terms of hh:mm from a text box and do addtion, minus and division? right now the method is very clumsy and i have not found how to do divison.

for eg 1:30 - 0:30 - 0:20
and 1:30 divided by 3
 

mjcoon

Well-Known Member
Licensed User
These time calculations are easily done in terms of "ticks" even though each tick represents only 1/10,000,000 of a second (as the Help for Time keywords explains).

The crucial thing for converting between tick that you can calculate and the usual format hh:mm is to use the TimeFormat() keyword.

Then there is the problem that even though you may just want to consider time-of-day the value in ticks always includes the date (in ticks since January 1, AD 0001; another huge number!)

But so long as you compare two times the system will assume that both refer to today's date and subtracting the earlier from the later will give the number of ticks between. As the Help says:
The value returned is the time entered and the current date.
Example:
T = TimeParse ("21:34")

Having done a calculation you can render the answer back into time format by doing Time(number_of_ticks), and ignore the fact that the system will think that refers to the time on January 1, AD 0001.

Or you can do a display in terms of minutes (for example) by dividing by the corresponding constant such as cTicksPerMinute. (See the topic "Constants" in the Help, sub-topic "Date and time".)

HTH, Mike.
 

jagr

Member
ah ok i get it now. i did a timeparse("01:30")/3 and it didnt work
now I get what Ticks is I did a (timeparse("01:30")-timeparse("00:00"))/3

thanks!
 
Top