cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Timestamp time difference

Carl985
10-Marble

Timestamp time difference

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PaiChung
22-Sapphire I
(To:Carl985)

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.

View solution in original post

8 REPLIES 8
PaiChung
22-Sapphire I
(To:Carl985)

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

PaiChung
22-Sapphire I
(To:Carl985)

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 ?

PaiChung
22-Sapphire I
(To:Carl985)

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

wcui
14-Alexandrite
(To:Carl985)

Hi Car1985, please refer to below screenshot to find the standard DateDifference snippet service.

Carl985
10-Marble
(To:wcui)

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

Carl985_0-1617793118599.pngCarl985_1-1617793172891.png

 

PaiChung
22-Sapphire I
(To:Carl985)

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.

Top Tags