Every Friday, the owner of a small bookkeeping firm does the same chore. Open each client invoice, find the date it went out, add 30 days on a calendar, and count how many days are left. It takes a while, and every so often a late invoice slips past because someone counted wrong.
That chore is just date math. JavaScript treats a date as a number underneath, so it can add 30 days and count the days between two dates with no calendar at all. Three small functions turn a list of invoice dates into a reminder list.
This is the code from my free lesson. You can run all of it in JSFiddle (no account needed).
The page: a heading and an empty list
In JSFiddle's HTML panel:
<h3>Invoice reminders</h3>
<ul id="list"></ul>
JavaScript will fill that empty list.
Today, and where the list is
In the JavaScript panel:
const today = new Date('2026-10-24T00:00');
const list = document.querySelector('#list');
Today is fixed at 24 October 2026 so your output matches mine. At work you write const today = new Date(); and it's always the real today.
The T00:00 matters. Without it, new Date('2026-10-24') is read as midnight UTC, which is the evening before in the US. With it, the date is midnight local time.
Function 1: add 30 days (Net 30)
function dueDate(issued) {
const d = new Date(issued + 'T00:00');
d.setDate(d.getDate() + 30); // Net 30
return d;
}
getDate() is the day of the month. Adding 30 and setting it back rolls over the month end for you: 10 September plus 30 days is 10 October. No "how many days in September" logic.
If a client is on Net 15 or Net 45, this is the one line you change. The rule lives in one place.
Function 2: count the days left
function daysLeft(due) {
return Math.round((due - today) / 86400000); // ms in a day
}
Subtracting two dates gives milliseconds. There are 86,400,000 milliseconds in a day, so dividing gives days. A negative number means the due date has already passed.
Math.round isn't just tidying. When a range crosses a daylight saving change (US clocks go back on 1 November), one "day" is 25 hours long, and for Harbor Accounting below the division comes out as 21.04 instead of 21 (in spring it would be 20.96). Rounding fixes both.
Function 3: write one reminder line
function remind(client, issued) {
const due = dueDate(issued);
const left = daysLeft(due);
const note = left < 0 ? 'OVERDUE by ' + -left + ' days' : 'due in ' + left + ' days';
list.innerHTML += '<li>' + client + ': ' + due.toDateString() + ', ' + note + '</li>';
}
The ? : picks between two texts: OVERDUE when the days are below zero, otherwise "due in". -left drops the minus sign, so -14 reads as "OVERDUE by 14 days". The last line adds one item to the list.
One line per open invoice
remind('Maple Dental', '2026-09-10');
remind('Cobalt Legal', '2026-09-28');
remind('Harbor Accounting', '2026-10-15');
Click Run. The result panel shows:
- Maple Dental: Sat Oct 10 2026, OVERDUE by 14 days
- Cobalt Legal: Wed Oct 28 2026, due in 4 days
- Harbor Accounting: Sat Nov 14 2026, due in 21 days
I re-ran the same code in Node today to check, and the three lines match the lesson exactly.
Why three functions instead of one
You could cram all of this into one loop. Splitting it up pays off the first time something looks wrong:
-
dueDate('2026-09-10')should be 10 October. Check it on its own. -
daysLeftshould be negative for a past date. Check it on its own. -
remindonly writes text.
When the firm changes its terms, you edit one line in dueDate and every reminder follows.
Taking it to real work
- Change the first line to
new Date(). - Replace the three
remind(...)lines with your open invoices. If they're in a spreadsheet, a formula like="remind('"&A2&"', '"&TEXT(B2,"yyyy-mm-dd")&"');"writes the lines for you. - Sort the overdue ones to the top, or color them red, once the basics work.
It's a small page, not an accounting system. But it's the Friday chore done in a second, and nobody counts on their fingers.
Practice it step by step
The lesson, JavaScript: Turn Invoice Dates into Due-Date Reminders, has you type every line yourself on real JSFiddle screens, and it checks each step. It's module 2 of the free JavaScript for Small Business course, which starts with an instant quote calculator for your website. There's also a one-page JavaScript cheat sheet for the whole course.
Practice it step by step, free: https://learn.ynteractive.com/content/js-due-date-reminders

Top comments (0)