Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
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
Solved! Go to Solution.
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.
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.