"Time" plus and minus

Just starting out? Need help? Post your questions and find answers here.
A M S
User
User
Posts: 58
Joined: Fri Aug 14, 2009 2:26 pm
Location: Afghanistan

"Time" plus and minus

Post 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 :D
Little John
Addict
Addict
Posts: 4791
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: "Time" plus and minus

Post by Little John »

AddDate()

You can add positive or negative values.

Regards, Little John
User avatar
RichAlgeni
Addict
Addict
Posts: 935
Joined: Wed Sep 22, 2010 1:50 am
Location: Bradenton, FL

Re: "Time" plus and minus

Post 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
A M S
User
User
Posts: 58
Joined: Fri Aug 14, 2009 2:26 pm
Location: Afghanistan

Re: "Time" plus and minus

Post by A M S »

thanks, but if :

02:00:11.565 + 15.353 mili sec >>>>>>>>> ??? output

have u a example for mili-sec model?
User avatar
RichAlgeni
Addict
Addict
Posts: 935
Joined: Wed Sep 22, 2010 1:50 am
Location: Bradenton, FL

Re: "Time" plus and minus

Post 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.
A M S
User
User
Posts: 58
Joined: Fri Aug 14, 2009 2:26 pm
Location: Afghanistan

Re: "Time" plus and minus

Post 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 ?
User avatar
RichAlgeni
Addict
Addict
Posts: 935
Joined: Wed Sep 22, 2010 1:50 am
Location: Bradenton, FL

Re: "Time" plus and minus

Post 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
Little John
Addict
Addict
Posts: 4791
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: "Time" plus and minus

Post 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
A M S
User
User
Posts: 58
Joined: Fri Aug 14, 2009 2:26 pm
Location: Afghanistan

Re: "Time" plus and minus

Post by A M S »

TanQ so math , very nice codes :D
Post Reply