www.ClassicTW.com
https://mail.black-squirrel.com/

TWX DateDiff?
https://mail.black-squirrel.com/viewtopic.php?f=15&t=33951
Page 1 of 1

Author:  Micro [ Wed Apr 24, 2013 11:53 am ]
Post subject:  TWX DateDiff?

Is there any way to get the elapsed hours/minutes/seconds between two dates in TWX like the VB DateDiff function does?

Author:  ElderProphet [ Sat Apr 27, 2013 2:01 pm ]
Post subject:  Re: TWX DateDiff?

I included a FORMAT command in one of the last builds of TWX 2.05, though I'm not sure if it's present in any of the versions floating around. You'll have to try this example to see if it compiles. The syntax is as follows:
format InputVar OutputVar CONSTANT

The constant of interest here is STRTODATETIME, which will convert a date and time value to a real number, representing days elapsed since the beginning of 1900... including the fractional part. So to determine the time elapsed between two string values, you'd do something like this:
Code:
format "4/27/2013 14:20:00" $dateTime1 STRTODATETIME
setVar $now DATE & " " & TIME  \\ date and time are TWX constants
format $now $dateTime2 STRTODATETIME
setPrecision 10
setVar $elapsed ($dateTime2 - $dateTime1)
echo "*Elapsed: " $elapsed

Lines 2 and 3 could be combined, but I've written them this way for clarity. You would need to convert the resulting fractional part to hours, minutes, and seconds if required.

Author:  Micro [ Fri May 03, 2013 4:39 pm ]
Post subject:  Re: TWX DateDiff?

Works Great... Thanks EP :)

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/