Page 1 of 1
"Time" plus and minus
Posted: Fri May 18, 2012 5:43 am
by A M S
for example :
02:00:11 + 15 sec >>>>>>>>> 02:00:26 output
is there a library or trick ???
i need a sure & stable solution .please

Re: "Time" plus and minus
Posted: Fri May 18, 2012 6:25 am
by Little John
AddDate()
You can add positive or negative values.
Regards, Little John
Re: "Time" plus and minus
Posted: Fri May 18, 2012 2:24 pm
by RichAlgeni
Just to show an alternative, you could do your calculations on the internal format of Date(), which gives you the number of seconds elapsed since 01/01/1970 0:00:00.
There are 86400 seconds in a day, 3600 in an hour, and so on.
Code: Select all
Define timerVar.i = Date(2012,05,18,02,00,11)
Debug timerVar
timerVar = timerVar + 15
Debug timerVar
Debug FormatDate("%mm/%dd/%yyyy %hh:%ii:%ss", timerVar)
Debug FormatDate("%hh:%ii:%ss", timerVar)
- 1337306411
1337306426
05/18/2012 02:00:26
02:00:26
Re: "Time" plus and minus
Posted: Sat May 19, 2012 2:27 am
by A M S
thanks, but if :
02:00:11.565 + 15.353 mili sec >>>>>>>>> ??? output
have u a example for mili-sec model?
Re: "Time" plus and minus
Posted: Sat May 19, 2012 2:36 am
by RichAlgeni
You can use ElapsedMilliseconds(), but you'll have to offset the value at the beginning of your logic with Date(), as ElapsedMilliseconds() only gives time values with regards to the amount of time the computer has been running, and not to a specific start date and time.
Re: "Time" plus and minus
Posted: Sat May 19, 2012 2:49 am
by A M S
thanks, i need a simple plus by times whit mili-sec sensitives, i have A and B at ready then: A + B = AB

sorry for my bad eng lng
please give me a example whit mil-sec ?
Re: "Time" plus and minus
Posted: Sat May 19, 2012 3:48 am
by RichAlgeni
Note that I have multiplied Date() * 1000, then added milliseconds after the decimal point. I have done it this way so that we can use integers, and don't have to deal with floating point numbers.
Floating point numbers are not as precise as integers. If you're not sure why, do a google search on floating point numbers. You will need to divide the result by 1000 to get a number that can be used by the Date() function.
Code: Select all
Define thisElapsed.i = ElapsedMilliseconds()
Debug thisElapsed
Define moduloElapsed.i = thisElapsed % 1000
Debug moduloElapsed
Define rightNow.i = Date()
Debug rightNow
rightNow = (rightNow * 1000) + moduloElapsed
Debug rightNow
Output:
3739316
316
1337381092
1337381092316
Re: "Time" plus and minus
Posted: Sat May 19, 2012 5:42 am
by Little John
A M S wrote:please give me a example whit mil-sec ?
Code: Select all
Define time_ms.q ; holds a time value, measured in milliseconds
; May 18th 2012, 2 hours, 0 minutes, 11 seconds, 243 milliseconds
time_ms = Date(2012,05,18, 02,00,11)*1000 + 243
; add 2521 milliseconds
time_ms + 2521
; display resulting time (year-month-day, hours:minutes:seconds:milliseconds)
Debug FormatDate("%yyyy-%mm-%dd, %hh:%ii:%ss:", Int(time_ms/1000)) + Str(time_ms%1000)
Regards, Little John
Re: "Time" plus and minus
Posted: Sat May 19, 2012 12:35 pm
by A M S
TanQ so math , very nice codes
