Strange behaviour on a specific date

I'm investigation a strange behaviour only happening once a year ( on the 31th of december)

We have three Ignition servers running at a customer, all three have been returning a strange date on the 31th of december in a mySQL database used to log data
the timestamp for the date is extracted using sytem.date.now,
system.date.format is used to format the date for the database

Ignition SCADA Version
Ignition version 8.1.29
Operating system : Linux
Timezone : Europe/Brussels

image

Source code used

def writeQuery_mysql(Variable_name):

	Datetime = (system.date.format(system.date.now(),"YYYYMMddHHmmssSSS"))[0:19]
	State = stateGantryMysql(Variable_name)
	row = {"Dt": Datetime, "Variable_name": Variable_name, "State": State}
	try:
		if State != '':
			system.db.runNamedQuery("logbook/rss_logbookmysql",row)
	except:
		pass

named query
INSERT INTO logboekmysql (Datetime, Variable_name, State) VALUES (:Dt, :Variable_name, :State);

Example of logged data
the data below has been logged on the 31th of december 2023

behaviour detected
the datetime returned on the 31 first of december 2023 has been logged one year in the future.
All logged records on other date times are correct. All other loggings ar correct

question
is it possible that system.date.now() is returining a wrong value on the 31th of december?

Don't know exactly but what I can tell you is you should turn your Dt named query parameter to a DataType of DateTime and then in your script do Datetime = system.date.now() instead of formatting it as a string.

And if your database is not using a datetime type for that column, do so.

Use the appropriate datatypes and these sort of issues won't happen. I can't say for sure what is going here, but I would say using datetimes appropriately probably resolves it.

I do not believe that system.date.now() gives a wrong date on a particular day of the year.

You are using capital YYYY in your format. You probably should be using lower-case yyyy. See why here:

4 Likes

ISO week-years strike again:

4 Likes

Yest, that is likely the cause of the problem.
I did not write this code, so I was not suspecting there could be a yyyy versus a YYYY
Thank you, very much

1 Like