Skip to main content
1-Visitor
April 13, 2018
Solved

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

  • April 13, 2018
  • 2 replies
  • 4875 views

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

Best answer by CarlesColl

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.

2 replies

5-Regular Member
April 13, 2018

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

1-Visitor
April 13, 2018

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.

ras1-VisitorAuthor
1-Visitor
April 16, 2018

Thanks @CarlesColl