How to extract Unix timestamp from tag read?

Hi everyone,

How can I get the unix timstamp out of this return from a system.tag.read command?

## Call
path = system.tag.read("[]MyTagPath")
print path

## Return
[1737.9868, Good, Sat Jun 18 16:56:10 CDT 2022 (1655589370000)]

## Preferred Return
1655589370000

system.tag.read().timestamp gives me the ordinary date time format and I’m struggling to convert it to unix in the script console.

Thank you,

Try this in the Script Console.

path = system.tag.read("[]MyTagPath")
print type(path)
print path.getValue()
print path.getTimestamp()
print system.date.toMillis(path.getTimestamp())

You can read more about the data type here:
http://files.inductiveautomation.com/sdk/javadoc/ignition80/8.0.0-beta/com/inductiveautomation/ignition/common/model/values/BasicQualifiedValue.html

Someone else may have a more terse solution.

1 Like

The timestamp you get from a QualifiedValue is a java.util.Date, on which you can call getTime().

2 Likes

Thank you both! For others, here is an example of the result.

## Call
reading_time = system.tag.read("[]MyTagPath")
print reading_time.timestamp.getTime() / 1000

## Result
1655643395