Page 1 of 1

Elapsed time

Posted: Tue Jan 22, 2008 8:54 pm
by Timoh
How do I calculate elapsed time?

I'm writing %%System Time.TimeAndDate%% to a User Time property called "HVAC.AC Run".
Then a few minutes later I'm trying to perform
%%System Time.TimeAndDate%%-%%HVAC.AC Run%% and sending it to a User TimeSpan property.

Obviously it's not working and I'm getting th error...
Unable to parse default time span value ["Year=2008, Month=01, Day=22, Hour=20, Minute=42, Second=41"-"Hour=00, Minute=00"]

Thanks
Tim

Posted: Wed Jan 23, 2008 3:58 am
by yaccri
If what you are trying to do is to set a device after some time, you can use a sleep timer and a related task.

Posted: Wed Jan 23, 2008 9:20 am
by Timoh
No... I'm trying to calculate how long a device has been running. Or how long a property had the same value before it changed
Tim

Posted: Fri Jan 25, 2008 10:14 pm
by Timoh
Anyone? Scott?

How do a calculate how long a property has had the same value?

i.e. Property Values...
Fan (boolean)
Fan Run Time (Time and Date)
Fan Elapsed (Timespan)

When Fan changes from 0 to 1, I write the system time to the Fan Run Time property.

When Fan changes back to 0, I need to know who long it was set to 1.
I'm trying "System Time"-"Fan Run Time" using PV and in a script and can't get it to work, nor can I think of another way to do it without parsing out the time string completely in a script.

Tim

Posted: Fri Jan 25, 2008 11:09 pm
by spike5884
Check DateDiff function in VBScript

Here is a sample that shows the duration in minutes:

Code: Select all

StartTime = GetPropertyValue( "TestTimeScript.StartTime" )
CurrentTime = GetPropertyValue( "System Time.TimeAndDate" )

MsgBox DateDiff("n",StartTime,CurrentTime)
TestTimeScript.StartTime is a Time property set to handle Time and Date.

Posted: Sat Jan 26, 2008 4:38 am
by Richard Naninck
It's too bad we don't have a simple epoch date available. Meaning amount of seconds from a baseline like 01-01-1978 or so until now. That always gives a single value in seconds and it is very easy to calculate time differences in seconds of of it.

I am with Spike. Have a task put your start time in a property and use a different property for end time. Once end time gets set, trigger a script that calculates the difference using DateDiff. That way you can be sure all remains fine even when the fan is turned on just before midnight and turned off just after midnight. It might be possible using stuff you wrote in your first post, but I haven't used that much so I couldn't tell you why or what goes wrong.

If you have a running script doing your fan control for you, you might even run all of these variables internally in the script without having to create tasks and properties to trigger and store these values.

Posted: Sat Jan 26, 2008 4:02 pm
by ScottBot
I think a script is your best option too. It would be nice if a timespan could be initialized with the result of the difference/subtraction of two date properties... but it doesn't work that way now. Nice feature request though.