Use clock_timestamp()
for current moment
now()
is a traditional PostgreSQL equivalent to transaction_timestamp()
which in turn is equivalent to CURRENT_TIMESTAMP
. These three commands return the moment when the transaction began. See manual.
To get the start time of the current statement, more specifically, the time of receipt of the latest command message from the client, call statement_timestamp()
.
To capture the moment when the function executes, call clock_timestamp()
.
Setting default time zone
You can set the default time zone in either of two ways, as discussed here:
- SQL-standard:
SET TIME ZONE 'Africa/Cairo' ;
- Postgres-specific: SET timezone TO 'Africa/Cairo' ;
Example
Here is a screenshot showing three things:
- Current moment as seen in UTC, in the web site Time.is.
- A query showing current default time zone, and the current moment.
- A query (a moment later, as I switched windows) showing a change to the current default time zone, along with a query for current zone and the current moment.
For this demo I used the managed database service by DigitalOcean.com for Postgres 12.

We can see in this shot that the current moment in UTC is 2:30 AM. The west coast time in US is 7:30 PM the prior day, seven hours behind UTC. The current default time zone in the first session is UTC (GMT), showing a correct time of 2:30 AM, in agreement with Time.is web site. The second session we switch to Africa/Cairo
time zone, to find the current moment seen through that time zone is 4:30 AM, two hours ahead of UTC.
All this makes sense, and seems correct to me.
Based on other's comments, I suspect the system clock of your host computer is incorrect. I wonder if the time zone on the server is set to one time zone, but the actually time-of-day is set to the current time of a different time zone. This would only happen if manually set by a sysadmin, I expect, as the host OS should auto-correct if set to check a time server.
To verify this, I suggest you do something similar to what I did, to verify the database server’s clock:
- Open a browser window for Time.is, selecting UTC.
- Set current default time zone to UTC:
SET TIME ZONE 'GMT' ;
.
- Query database for current default time zone and the current moment. Use
clock_timestamp
rather than a transaction-start function like now
to avoid confusion with a long-running txn.
➥If Time.is does not agree with your result from clock_timestamp
, then we know your server time is set incorrectly.
Take a screenshot, post with your Question.
Tips:
- Learn to think, work, log, and debug in UTC. Forget about your own parochial time zone while on the job. Think of UTC as the One True Time, and all other zones are but mere variations.
- Generally best to set your servers to UTC (offset of zero hours-minutes-seconds).
- I recommend configuring your servers to check with a time server for auto-correction of their clocks, if you have access to reliable time servers.