Using the "Qualified Value" Timestamp

I’m trying to use the qualified value from a system.tag.read with a MSSQL stored procedure that I’m passing the “.timestamp” value to. I keep getting the error “The conversion from UNKNOWN to DATE is unsupported.” Playing around with script editor, and running this code:

tagVal = system.tag.read("SP_Test_Tag") print tagVal print tagVal.value print tagVal.quality print tagVal.timestamp

I get:
[1, Good, Wed May 04 22:01:30 CDT 2016]
1
Good
Wed May 04 22:01:30 CDT 2016

First, will this not give me the millisecond timestamp and secondly, how the heck do I convert this into a datetime that I can pass to the stored procedure?

The timestamp field is a java.util.Date(). When printed by python, Date() is implicitly converted to a string with a default format that leaves off the milliseconds. Passing the Date() object directly as a parameter of stored procedure in scripting or as a ‘?’ substitution in a prepared query will retain the millisecond precision.
When pulling data from a database, timestamp and datetime columns return a java.sql.Timestamp(), which behaves mostly like a java.util.Date() (it’s a subclass), but with nanosecond precision available, and a default string format that includes fractional seconds.

1 Like

Phil,
Thanks for the background on that. Python is new to me so still trying to figure that out. I would like to use the time stamp returned from the valueChanged event on a tag. Is there a Python function that will convert the time stamp in the valueChanged into something MSSQL can use?

Thanks,
Bryan

[quote=“BearBry”]Thanks for the background on that. Python is new to me so still trying to figure that out.[/quote]These types are actually from java but usable in the Jython flavor of Python. Necessary in this case because the underlying framework (Ignition) is all java.[quote=“BearBry”]I would like to use the time stamp returned from the valueChanged event on a tag. Is there a Python function that will convert the time stamp in the valueChanged into something MSSQL can use?[/quote]No conversion required, as long as you don’t convert it to a string. Include it as a value substitution using ‘?’ in one of the system.db.Prep() functions. Or assign it with .registerInParam() to an input to a stored procedure. Note that braces {} in SQL statements in Ignition do perform a string conversion.