# SQLite date(): add days and months, start and end of month

Source: https://sqlstreak.com/sql/functions/date · Tested on PostgreSQL 18.6 and SQLite 3.54.1; results generated 2026-11-22.


**Short answer:** `date(value, modifier, …)` returns a date as `'YYYY-MM-DD'` text after applying the modifiers in order: `date('2026-03-15', '+7 days')` is `'2026-03-22'`. PostgreSQL does the same with date arithmetic: `DATE '2026-03-15' + 7`.

## Syntax

- PostgreSQL: `DATE '2026-03-15' + 7  /  d + INTERVAL '1 month'  /  date_trunc('month', d)::date` (No date() function: use date arithmetic and date_trunc)
- SQLite: `date(time_value [, modifier, …])  -- modifiers: '+N days', '+N months', 'start of month', 'weekday N', …` (Yes, built in)

## Examples

### A trial that ends 30 days after sign-up

PostgreSQL:

```sql
SELECT id, signed_up_on,
       signed_up_on + 30 AS trial_ends
FROM users
ORDER BY id
LIMIT 5;
```

SQLite:

```sql
SELECT id, signed_up_on,
       date(signed_up_on, '+30 days') AS trial_ends
FROM users
ORDER BY id
LIMIT 5;
```

Result (both engines):

| id | signed_up_on | trial_ends |
| --- | --- | --- |
| 1 | 2026-01-01 | 2026-01-31 |
| 2 | 2026-01-02 | 2026-02-01 |
| 3 | 2026-01-02 | 2026-02-01 |
| 4 | 2026-01-02 | 2026-02-01 |
| 5 | 2026-01-03 | 2026-02-02 |

### Group by the first day of the month

PostgreSQL:

```sql
SELECT date_trunc('month', played_on)::date AS month_start, COUNT(*) AS plays
FROM plays
GROUP BY month_start
ORDER BY month_start;
```

SQLite:

```sql
SELECT date(played_on, 'start of month') AS month_start, COUNT(*) AS plays
FROM plays
GROUP BY month_start
ORDER BY month_start;
```

Result (both engines):

| month_start | plays |
| --- | --- |
| 2026-01-01 | 274 |
| 2026-02-01 | 635 |
| 2026-03-01 | 1015 |
| 2026-04-01 | 483 |

### The last day of each hire month

PostgreSQL:

```sql
SELECT name, hired_on,
       (date_trunc('month', hired_on) + INTERVAL '1 month - 1 day')::date AS month_end
FROM staff
ORDER BY hired_on
LIMIT 5;
```

SQLite:

```sql
SELECT name, hired_on,
       date(hired_on, 'start of month', '+1 month', '-1 day') AS month_end
FROM staff
ORDER BY hired_on
LIMIT 5;
```

Result (both engines):

| name | hired_on | month_end |
| --- | --- | --- |
| Rosa Vega | 2024-01-10 | 2024-01-31 |
| Omar Haddad | 2024-03-01 | 2024-03-31 |
| Ben Carter | 2024-04-20 | 2024-04-30 |
| Lia Moreau | 2024-06-15 | 2024-06-30 |
| Ivan Petrov | 2024-08-01 | 2024-08-31 |

## Edge cases, measured on both engines

| Case | PostgreSQL | SQLite |
| --- | --- | --- |
| Plus 7 days | '2026-03-22' | '2026-03-22' |
| Plus 1 month from 31 January | '2026-02-28' | '2026-03-03' |
| Start of month | '2026-03-01' | '2026-03-01' |
| Last day of February 2024 | '2024-02-29' | '2024-02-29' |
| Next Monday on or after | not available | '2026-03-16' |
| 30 February | error: date/time field value out of range: "2026-02-30" | '2026-03-02' |
| Text that isn't a date | error: invalid input syntax for type date: "March 1" | NULL |
| A timestamp loses its time | '2026-03-15' | '2026-03-15' |
| SQLite's modifiers in PostgreSQL | error: function date(unknown, unknown) does not exist | not available |

## Common mistakes

- Adding a month to the 29th, 30th or 31st: SQLite and PostgreSQL disagree (see the matrix). Go to the start of the month first if that matters.
- Putting modifiers in the wrong order: they apply left to right.
- Using SQLite's modifiers in PostgreSQL: `date(d, '+7 days')` fails there (see the matrix). Add an integer or an INTERVAL instead.
