0
0
PostgreSQLquery~5 mins

CURRENT_DATE, CURRENT_TIMESTAMP, NOW() in PostgreSQL

Choose your learning style9 modes available
Introduction

These functions help you get the current date and time from the database server. This is useful when you want to know when something happened or to track time.

You want to record the date when a user signs up.
You need to find out the current time to log an event.
You want to filter records created today.
You want to compare dates to check if a deadline has passed.
Syntax
PostgreSQL
CURRENT_DATE
CURRENT_TIMESTAMP
NOW()

CURRENT_DATE returns only the current date (year-month-day).

CURRENT_TIMESTAMP and NOW() return the current date and time (timestamp with time zone).

Examples
Returns the current date without time.
PostgreSQL
SELECT CURRENT_DATE;
Returns the current date and time.
PostgreSQL
SELECT CURRENT_TIMESTAMP;
Also returns the current date and time, same as CURRENT_TIMESTAMP.
PostgreSQL
SELECT NOW();
Sample Program

This query shows all three functions together so you can see their outputs side by side.

PostgreSQL
SELECT CURRENT_DATE AS today, CURRENT_TIMESTAMP AS now_timestamp, NOW() AS now_function;
OutputSuccess
Important Notes

The exact time shown depends on when you run the query.

Use CURRENT_DATE when you only need the date without time.

NOW() and CURRENT_TIMESTAMP are interchangeable in PostgreSQL.

Summary

CURRENT_DATE gives you just the date.

CURRENT_TIMESTAMP and NOW() give you date and time.

These functions are useful for tracking and comparing dates and times.