Source language: Translate to:

Difference between 2 dates and Hours

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Difference between 2 dates and Hours

Postby Alex » Mon Jan 11, 2010 2:52 am

Hi,

It is possible to calculate the difference in milliseconde between 2 dates and 2 hours?

For example:

Hour Format 24H

01/09/2010 11:45 and 01/10/2010 02:13

Thanks


Alex
Alex
 
Posts: 745
Joined: Sat Mar 04, 2006 4:53 am

Postby Neosoft Support » Mon Jan 11, 2010 11:33 am

The following calculates the difference in seconds between two dates ([Date1],[Date2]) and two times ([Time1],[Time2]):

Code: Select all
.Convert time1 to seconds since midnight
SubStr "[Time1]" "1" "2" "[H]"
SubStr "[Time1]" "4" "2" "[M]"
SubStr "[Time1]" "7" "2" "[S]"
Math "([H]*3600)+([M]*60)+[S]" "0" "[T1]"

.Convert time2 to seconds since midnight
SubStr "[Time2]" "1" "2" "[H]"
SubStr "[Time2]" "4" "2" "[M]"
SubStr "[Time2]" "7" "2" "[S]"
Math "([H]*3600)+([M]*60)+[S]" "0" "[T2]"

.Convert date1 to days
DateToNum "[Date1]" "m/d/y" "[D1]"

.Convert date2 to days
DateToNum "[Date2]" "m/d/y" "[D2]"

.subtract date2 from date1 and convert to seconds
Math "([D2]-[D1])*86400" "0" "[ElapsedDaysAsSeconds]"

.subtract time2 from time1
Math "[T2]-[T1]" "0" "[ElapsedSeconds]"

.combine elapsed days as seconds and seconds
Math "[ElapsedDaysAsSeconds]+[ElapsedSeconds]" "0" "[ElapsedTime]"

.display the results
AlertBox "Result" "Elapsed time is: [ElapsedTime] seconds"
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5603
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Postby Alex » Mon Jan 11, 2010 12:29 pm

Hello,

Thank you very much for your answer.

And to convert into milliseconde it is:

Code: Select all
Math "1000*[ElapsedTime]" "0" "[milltime]"


Thanks


Alex
Alex
 
Posts: 745
Joined: Sat Mar 04, 2006 4:53 am


Return to NeoBook Action Commands

Who is online

Users browsing this forum: Exabot [Bot] and 1 guest

cron