PostgreSQL current_date Function: How to Use It
In this article
The PostgreSQL current_date function returns the current date according to the server’s time zone, without any time component. It’s useful for filtering records by today’s date, setting default values in tables, or logging events without timestamps. No installation or setup is needed beyond having a working PostgreSQL connection, as current_date is a built-in function available in all modern versions.
What You'll Need
- A working PostgreSQL server (version 9.0 or later)
- Access to a database via psql, pgAdmin, DBeaver, or any SQL client
- Basic understanding of SQL syntax and executing queries
- Permission to run SELECT queries on the database
Step-by-Step
- Connect to your PostgreSQL database using your preferred client. For example, open a terminal and type
psql -U username -d database_name, then enter your password when prompted. - Once connected, execute a simple query to retrieve the current date:
SELECT current_date;Press Enter. The result will display the date in YYYY-MM-DD format, such as2024-06-15. - To use current_date in a WHERE clause to filter records, run a query like:
SELECT * FROM orders WHERE order_date = current_date;This returns all rows where the order_date column matches today’s date. - Set current_date as a default value for a date column when creating a table. For example:
CREATE TABLE logs (id SERIAL PRIMARY KEY, event_date DATE DEFAULT current_date, message TEXT);Any new row inserted without a specified event_date will automatically use today’s date. - Combine current_date with date arithmetic. For example, to find records from the last seven days:
SELECT * FROM sales WHERE sale_date >= current_date - 7;PostgreSQL allows simple integer subtraction to subtract days from a date. - Compare current_date with a timestamp column by casting the timestamp to date:
SELECT * FROM events WHERE event_timestamp::date = current_date;This ensures you’re comparing date-only values, avoiding mismatches due to time components. - Use current_date in an INSERT statement:
INSERT INTO users (name, registration_date) VALUES ('Alice', current_date);This avoids hardcoding dates and ensures accuracy regardless of when the query runs. - Test the function in different time zones by checking your server’s time zone setting:
SHOW timezone;The value returned affects what current_date outputs. If your server is in UTC and you’re in New York, current_date may reflect yesterday’s date in your local time. - For debugging, combine current_date with other functions:
SELECT current_date, current_date + 1 AS tomorrow, current_date - 30 AS one_month_ago;This helps validate date arithmetic is working as expected.
Common Mistakes
- Confusing current_date with now() or current_timestamp — these include time and will not match a date-only column unless cast.
- Using current_date as a string literal, such as WHERE date_column = 'current_date' — this treats it as text, not a function, and will return no results.
- Assuming current_date uses the client’s local time — it always uses the server’s system time zone, not the user’s device or browser time.
- Trying to update a column with current_date using an UPDATE statement without proper syntax:
UPDATE users SET last_login = current_date WHERE id = 1;is correct, butUPDATE users SET last_login = 'current_date'is not. - Expecting current_date to change during a long-running transaction — it returns the date when the transaction started, not the date when the query executes in a multi-statement transaction.
Tips
- Use current_date for date-only comparisons; use current_timestamp if you need both date and time precision.
- When building reports, alias the result for clarity:
SELECT current_date AS report_date; - Combine current_date with interval calculations:
current_date + interval '1 week'gives you the date one week from now. - For applications where users are in multiple time zones, store dates in UTC and convert for display — avoid relying on current_date for user-facing local dates.
- Use current_date in triggers to auto-populate audit fields, like created_at or updated_at, if you only care about the date, not the exact time.
- Always test date logic with known values. For example, if today is June 15, run
SELECT current_date = '2024-06-15'::date;to confirm the function returns the expected value. - When joining tables, ensure both sides are the same type — compare DATE to DATE, not DATE to TIMESTAMP.
Troubleshooting
- If
SELECT current_date;returns an error likefunction current_date does not exist, your PostgreSQL version is very old (pre-9.0). Upgrade to a supported version. - If your query returns no rows when you expect data, check if your table’s date column contains time components. Cast it with
::dateto match current_date. - If the date appears to be off by one day, check your server’s time zone with
SHOW timezone;and compare it to your local time. Adjust the server’s timezone setting if needed usingALTER DATABASE database_name SET timezone TO 'America/New_York'; - If current_date works in psql but not in your application, ensure your application’s database connection is not overriding the time zone or using a different connection pool with different settings.
- If you get a syntax error near current_date, double-check for typos — it’s one word, no parentheses:
current_date, notcurrent_date(). - When using an ORM like Django or Hibernate, ensure the framework isn’t wrapping current_date in quotes or converting it to a string. Use raw SQL or the ORM’s built-in date functions instead.
- If you’re using a cloud database (like AWS RDS or Google Cloud SQL), confirm the instance’s time zone hasn’t been manually changed from the default. Contact your provider’s support if unsure.