We can use SQLite’s DATE()
function to perform calculations on a given date. One of the things we can do is return the first, second, third, or fourth instance of a given day within a given month.
Example
Here’s an example to demonstrate:
SELECT
DATE('2025-10-20', 'start of month', 'weekday 1') AS "First",
DATE('2025-10-20', 'start of month', '+7 days', 'weekday 1') AS "Second",
DATE('2025-10-20', 'start of month', '+14 days', 'weekday 1') AS "Third",
DATE('2025-10-20', 'start of month', '+21 days', 'weekday 1') AS "Fourth",
DATE('2025-10-20', 'start of month', '+28 days', 'weekday 1') AS "Fifth";
Result:
First Second Third Fourth Fifth ---------- ---------- ---------- ---------- ---------- 2025-10-06 2025-10-13 2025-10-20 2025-10-27 2025-11-03
In this example, the starting date is the same for all instances, as well as most of the arguments. The only thing that changes is how much we add to the start of the month. If we don’t add anything, we can return the first Monday, adding 7 days returns the second Monday, and so on.
Here, we use start of month
to return the date back to the first day of the month. We then use more modifiers to modify that date accordingly.
The weekday 1
modifier moves the date forward to the next Monday (Sunday is 0, Monday is 1, Tuesday is 2, and so on).
To get the second Monday we can use +7 days
to advance the date forward by a week. For subsequent Mondays we add 7 days to that number (+14 days
, +21 days
, +28 days
etc).
We can also see that adding 28 days returns the first Monday of the following month.