How to Get the Current Date and Time (No Time Zone) in PostgreSQL
Database:
Operators:
Table of Contents
Problem
You’d like to get the current date and time in a PostgreSQL database. You don’t need the time zone offset.
Solution
We’ll use the function LOCALTIMESTAMP
to get the current date and time without any time zone information:
SELECT LOCALTIMESTAMP; |
Here’s the result of the query:
2023-09-24 20:10:58.977914
Discussion
The PostgreSQL function LOCALTIMESTAMP
returns the current date and time (of the machine running that instance of PostgreSQL) as a timestamp value. It uses the YYYY-MM-DD hh:mm:ss.nnnnnnn
format, where:
YYYY
is a 4-digit year.MM
is a 2-digit month.DD
is a 2-digit day.hh
is a 2-digit hour.mm
is a 2-digit minute.ss
is a 2-digit second.nnnnnn
are fractional seconds (from zero to 6-digit precision).

This function returns the time at which the current transaction started. The difference between LOCALTIMESTAMP
and CURRENT_TIMESTAMP
is that the LOCALTIMESTAMP
doesn’t include the time zone offset.