Home / SQL / Reference / Dates

SQL julianday()

Count the days between two dates in SQLite.

Syntax

julianday(date2) - julianday(date1)

julianday turns a date into a day number, so subtracting two gives the gap in days.

Example

Query (on the shop database used in the SQL course)

SELECT order_id, order_date,
       CAST(julianday('2025-12-31') - julianday(order_date) AS INTEGER) AS days_to_year_end
FROM orders
LIMIT 4;

Result

order_idorder_datedays_to_year_end
12025-06-10204
22025-05-17228
32025-03-25281
42025-10-2666

4 rows

Good to know. PostgreSQL: subtract dates directly (date2 - date1).

Related

Learn it step by step in the free lesson Functions: Text, Numbers, Dates & CASE, with exercises that check your queries.