DuckDB has a today()
function that returns the current date. It’s similar to the current_date
function, which does the same thing.
Here, we’ll look at how the today()
function works, along with some basic examples.
What is the today()
Function?
DuckDB’s today()
function is a built-in SQL function that returns the current date as a DATE
type. It returns the current date (at start of current transaction) in UTC.
The function does not require (or accept) any arguments.
Syntax
The syntax for the today()
function goes like this:
today()
So, no arguments are required, or accepted.
The function returns the current date in the format YYYY-MM-DD
.
Example
Here’s a basic example to demonstrate:
SELECT today();
Result:
+------------+
| today() |
+------------+
| 2025-02-11 |
+------------+
Adding a Time Interval to the Date
We can combine today()
with date operators to add a specified time interval to the current date:
SELECT
today(),
today() + INTERVAL 11 MONTH;
Result:
+------------+-------------------------------------------------------------------+
| today() | (today() + to_months(CAST(trunc(CAST(11 AS DOUBLE)) AS INTEGER))) |
+------------+-------------------------------------------------------------------+
| 2025-02-11 | 2026-01-11 00:00:00 |
+------------+-------------------------------------------------------------------+
When we added to the date, the result is a timestamp/datetime value, as opposed to just the date.
Also, the header of the second column implies that DuckDB used the to_months()
function, along with trunc()
and CAST()
to produce the result.
So we could use that method too:
SELECT (today() + to_months(CAST(trunc(CAST(11 AS DOUBLE)) AS INTEGER)));
Result:
+-------------------------------------------------------------------+
| (today() + to_months(CAST(trunc(CAST(11 AS DOUBLE)) AS INTEGER))) |
+-------------------------------------------------------------------+
| 2026-01-11 00:00:00 |
+-------------------------------------------------------------------+
But it’s a lot easier using the INTERVAL
operator.
Subtracting a Time Interval
Here’s a similar example, but this time we subtract an interval instead of adding it:
SELECT
today(),
today() - INTERVAL 11 MONTH;
Result:
+------------+-------------------------------------------------------------------+
| today() | (today() - to_months(CAST(trunc(CAST(11 AS DOUBLE)) AS INTEGER))) |
+------------+-------------------------------------------------------------------+
| 2025-02-11 | 2024-03-11 00:00:00 |
+------------+-------------------------------------------------------------------+
No Arguments
No arguments are accepted. Here’s what happens when we pass an argument:
SELECT today(1);
Result:
Binder Error: No function matches the given name and argument types 'today(INTEGER_LITERAL)'. You might need to add explicit type casts.
Candidate functions:
today() -> DATE
LINE 1: SELECT today(1);
^
The current_date
Function
DuckDB also has a current_date
function that does the same thing as today()
:
SELECT
current_date,
today();
Result:
+--------------+------------+
| current_date | today() |
+--------------+------------+
| 2025-02-11 | 2025-02-11 |
+--------------+------------+