Hi all,
In database, entry time is stored with column datatype as time with timezone. This db server is placed in UK region. So whenever new row inserts then date value stores as per UK time zone. We have requirement that this date should match with gateway server timezone. To do that we have written function to change time value into gateway timezone, But while converting that date into gateway specific timezone it shows wrong date time value. We have used java library functions to change date values but script is unable to return value in correct timezone.
Is there any solution to it?
The general recommendation is that timestamps are stored in UTC and then converted to desired timezone at the point of display.
You shouldn't need to use Java libraries as the system.date | Ignition User Manual functions should have what you need.
Which module are you using? Vision, Perspective, Reporting? Add the tag to your question title.
Have you set the Perspective timezone in Project Properties? Normally you want Client Timezone.
Yes, I set it to client timezone.
Are you sure that the column type in your database is storing the timestamp? Witch type of database are you using ?
The timestamp with timezone
column type in PostgreSQL (abbreviated as timestamptz
) doesn't actually store the timezone, but uses the timezone information to ensure the underlying column data is correct for UTC. In other words, it works exactly the same as the java.util.Date
object type in Ignition, and perfectly preserves the "instant in universal time" regardless of timezone settings in either the DB or the Ignition gateway. The timezone settings in Ignition for gateway and client then control how this is displayed and/or parsed from input.
If you have having difficulties with this, it is usually caused by failing to let Ignition and PostgreSQL handle those tasks. (Don't stringify your timestamps anywhere except for display.)