I need to get delta of timestamp in hours of two events
val = PrevEvent(tag,'*')
TimeDiff = '*' - val
The results in dd.HH:mm:ss.FFF
How Can I convert this time difference into hours in Pi Analytics engine.
Thanks in Advance
I am afraid there's no function that would allow you to get the sub second portion of a timestamp but assume this should be less of an issue because you are using unit hours.
Using Gregor's example, I think I can provide some help:
HoursDiff = Float(SnapshotTime-LatestArchiveTime)/3600
Converting a TimeSpan to float will give you the number seconds associated with the TimeSpan.
Then dividing by 3600 you get the hours.
P.D.: Yes, it honours DST changes
That’s help. You made my day
I'm glad it helped
Thanks Gregor, it works for time but it tricky if the values are at different dates. I mean if the values the 4-5 days ago then we have to calculate the delta for date and add it to calculation
I must admit that I have been lazy With Day() you get the amount of days for a given Timestamp and a day has 24 hours. So by adding the following you should be good.
Can you please try what Nicola suggested?
It's not only the most simple but as well appears to be the only solution that works reliable with bigger gaps between 2 events.
Wouldn't this work: SecSinceChange('Test')/3600
Retrieving data ...