Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Hi I want to get the difference between the timestamp value logged when a property updates on a thing. The thing has an valuestream. Do I need to write a service for this? Which snippets would I use? Or is there an existing service which would do this so it can be displayed in a mashup. Thanks in advance.
Solved! Go to Solution.
If you have a subscription on the property data change, you'll get new and old VTQ, subtract the new and old Time (T part of VTQ) and then convert the milliseconds to the time you want.
Depending on how and when you need it, when a property updates, if you subscribe to the datachange, you'll have new and old VTQ of the property as the input into the datachange subscription
else you'd have to pull from the value stream
I need to time difference on the timestamp when the property updates say property is good part, timestamp is 2021-04-5-16:00.00 then next timestamp is 2021-04-5-16:01.00 so time difference is 1 minute
If you have a subscription on the property data change, you'll get new and old VTQ, subtract the new and old Time (T part of VTQ) and then convert the milliseconds to the time you want.
Hi PaiChung,
I'm having difficulty getting the script to work can you show me how I do this? If the old value is infotable and the new value is also an infotable how do I subtract one from the other? Sorry my Java is not that good ?
You can just expand New and Old and grab the OldTimeStamp and NewTimeStamp fields from Inputs.
I think it'll look like something OldData.timestamp and NewData.timestamp (sorry don't have ThingWorx open right now)
Then use the DateDiff service available in Snippets/Date Time Functions
Hi Car1985, please refer to below screenshot to find the standard DateDifference snippet service.
would the date difference function be used in the subscription for the datachange or would it be used in a service? Thank you for your help
You can make the calculation directly in the subscription if you want, then you don't have to pass the new and old time to the service you are invoking.