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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

How to get time difference from two datetime widget in a textbox widget

ras
12-Amethyst
12-Amethyst

How to get time difference from two datetime widget in a textbox widget

Hi,

As I am new to Thingworx I don't know how to get time difference from two datetime widget in a textbox widget. Do I need to create service for this?

Thanks in advance

ACCEPTED SOLUTION

Accepted Solutions

If you want it in milliseconds ( of course then you can convert it), you can do it with an Expression widget with two DateTime parameters and on the expression you set:

(date1.getTime()-date2.getTime())

 

That's all you don't need a service neither a custom property for that.

View solution in original post

3 REPLIES 3
supandey
19-Tanzanite
(To:ras)

Hi @ras you can use a built in service called DateDifference() it takes DateTime datatype values and returns Number datatype which is basically miliseconds of difference in between those two dates

 

// date1:DATETIME
var date1 = new Date();
date1 = me.startDate;

// date2:DATETIME
var date2 = new Date();
date2 = me.endDate;

// dateDifference(date1:DATETIME,date2:DATETIME):NUMBER
var difference = dateDifference(date2, date1);

me.DateDifference = difference

logger.info("This is the difference in miliseconds" + me.DateDifference);

You can then bind the out put received to whatever widget you like. note in the above example I am storing and persisting the difference under my same thing which is why the difference is assigned to me.DateDifference

If you want it in milliseconds ( of course then you can convert it), you can do it with an Expression widget with two DateTime parameters and on the expression you set:

(date1.getTime()-date2.getTime())

 

That's all you don't need a service neither a custom property for that.

ras
12-Amethyst
12-Amethyst
(To:CarlesColl)

Thanks @CarlesColl

Announcements


Top Tags