I am writing a web interface for a database (PHP / Postgresql) in which I need to store different dates / times. The time should always be entered on the client side at local time and displayed in local time. For storage purposes, I save all dates / times as integers (UNIX timestamps) and normalize to UTC. One specific field has a limitation that the filled timestamp is not allowed in the future, so I tried this with a database constraint ...
CONSTRAINT not_future
CHECK (timestamp-300 <= date_part('epoch', now() at time zone 'UTC'))
. -300 - give a 5-minute delay in case of a bit of desynchronous time between the browser and server. The problem is that this limitation always fails when sending the current time. I tested and found the following.
In the PostgreSQL client:
SELECT now() - returns the correct local time
SELECT date_part('epoch', now()) - returns the unix timestamp in UTC (checked by supplying a value to the date function in PHP, correcting its compensation in my time zone)
SELECT date_part('epoch', now() at time zone 'UTC')- returns the unix timestamp at two offsets the time zone to the west, for example. I am in GMT + 2, I get the timestamp GMT-2.
, " " UTC " ", , "" unix, AFAIK UTC, "" UTC? , - / .