Measuring days between dates

Hello,

I am trying to get the days between 2 dates. First date is coming from a button press with this and I write it to date time memory tag.

time=system.date.now()
system.tag.write("[TSW_Production]Foaming/Denemeler/BakimZamani",(time))

Second date is coming from another value changed tag script like below and in the same value changed script I want to calculate the days between first date and second one. I want to write this day difference to another memory tag.

currenttime=system.date.now()
ptime=system.tag.read("[.]…/…/Denemeler/BakimZamani")
timedif=system.date.daysBetween(currenttime,ptime)
system.tag.write("[.]…/…/Denemeler/Bakimakalansure",(timedif))

But I do get error like this

Error executing script.
Traceback (most recent call last):
File β€œtagevent:valueChanged”, line 4, in valueChanged
TypeError: daysBetween(): 2nd arg can’t be coerced to java.util.Date

I think my first date which was written on a date time tag in a different event script cant get read properly in the system.date.daysBetween function. How can I get this to work?

Any help is much appreciated.

system.tag.read returns a qualified value object. Use

1 Like