How to Track Inventory Expiration Dates in Google Sheets with Email Alerts (Lots, FEFO, 2026)
Kitchens, cafés, food pantries, clinics, labs, salons and small shops often keep stock with an expiry date in a spreadsheet: food and drinks, medical and first-aid supplies, reagents, cosmetics, chemicals. The hard part isn't writing the date down, it's noticing in time that a box at the back of the store room runs out next week, and using the oldest stock first. This guide sets up one row per lot, color-codes what is about to expire, builds a “use this first” list, and adds a free Apps Script that emails each person one list of their lots that are close to expiring or already expired while still in stock.
If you already use an inventory or point-of-sale system with lot and expiry tracking, use its alerts. This guide is for when the sheet is the system. For equipment warranties and service dates, see the warranty expiration tracker and maintenance schedule reminders.
Step 1: a Lots tab with one row per lot
Track lots, not products. Two deliveries of the same item usually expire on different dates, so each delivery (or each batch with its own date) gets its own row. Name the tab Lots. The script finds columns by their header, so the order is up to you, but the formulas below assume A to H:
| Col | Header | What goes in it |
|---|---|---|
| A | Item | What it is, e.g. “Oat milk 1 L”, “Sterile gauze 4x4” |
| B | Lot | Optional lot or batch number from the label |
| C | Location | Optional: walk-in cooler, shelf 2, van 1 |
| D | Qty | How many are left. 0 stops alerts; blank counts as still in stock. |
| E | Expiry date | A real date (see month-only dates below) |
| F | Notify | Optional email of whoever looks after this stock. Blank = the script owner, or DEFAULT_TO. |
| G | Status | Blank while in stock. Used up, Sold, Discarded, Disposed, Returned, Written off or Donated stop alerts. |
| H | Sent log | Leave empty; the script records what it sent |
Add a helper column I, Days left, filled down from row 2: =IF(E2="","",E2-TODAY()). Negative means expired. Format column E as a date (Format › Number › Date) and give Status a Data › Data validation dropdown so the stop words are spelled the way the script expects.
Month-only dates. Labels often say only a month, like “EXP 03/2027”. That usually means the end of the month, but check the manufacturer's or supplier's convention for your products. If you type the label into column J, first formatted as Format › Number › Plain text so Sheets doesn't turn it into a date, this turns it into the last day of that month: =IF(J2="","",EOMONTH(DATE(RIGHT(J2,4),LEFT(J2,2),1),0)). Copy the result and paste it into Expiry date as a value.
“Use within N days of opening.” Some products get a shorter life once opened. Put the opened date in column K and use the earlier of the two dates: =IF(K2="",E2,MIN(E2,K2+28)), with 28 replaced by the product's own number. Again, paste it into Expiry date as a value, or point the script at that column by naming its header Expiry date instead.
Step 2: see what is expiring and what to use first
Select A2:I, open Format › Conditional formatting, choose Custom formula is, and add these rules in this order:
| Custom formula | Color | Meaning |
|---|---|---|
=OR(AND(ISNUMBER($D2),$D2<=0),REGEXMATCH(LOWER($G2),"^(used up|sold|sold out|discarded|disposed|returned|written off|donated)$")) | Grey text | Gone, no alerts |
=AND(ISNUMBER($E2),$E2<TODAY()) | Red | Expired and still in stock |
=AND(ISNUMBER($E2),$E2>=TODAY(),$E2<=TODAY()+30) | Amber | Expires in the next 30 days |
Conditional formatting stops at the first matching rule, so lots that are gone stay grey even after their date passes. For a “use first” list, the oldest-expiring lot of each item still in stock (first expired, first out, often called FEFO), put this on a summary tab:
=QUERY(Lots!A2:G, "select A, min(E), sum(D) where A is not null and E is not null and (D > 0 or D is null)" & " and not G matches '(?i)used up|sold|sold out|discarded|disposed|returned|written off|donated'" & " group by A order by min(E) label A 'Item', min(E) 'Use first (expires)', sum(D) 'In stock'", 0)
To see which lot that is and where it sits, list every lot in stock sorted by item and then by expiry; the first row of each item is the one to pick:
=SORT(FILTER(Lots!A2:E, Lots!A2:A<>"", ISNUMBER(Lots!E2:E), (Lots!D2:D="")+(Lots!D2:D>0), NOT(REGEXMATCH(LOWER(Lots!G2:G), "^(used up|sold|sold out|discarded|disposed|returned|written off|donated)$"))), 1, TRUE, 5, TRUE)
And how much of one item expires in the next 30 days (item name in A2 of the summary tab):
=SUMIFS(Lots!D2:D, Lots!A2:A, A2, Lots!E2:E, ">="&TODAY(), Lots!E2:E, "<="&TODAY()+30)
Step 3: email alerts before and after the expiry date
Google Sheets doesn't send email when a date arrives; its notification rules react to edits, not to the calendar. A short Apps Script with a daily trigger does it. Open Extensions › Apps Script, paste this and save. Then:
- Run
sendExpiryAlertsonce and approve the permissions.PREVIEWistrue, so every email goes to you, with the real recipient in the subject, and nothing is logged. - Read the preview emails. When they look right, set
PREVIEW = falseand save. - Add the trigger: Triggers › Add trigger › sendExpiryAlerts › Time-driven › Day timer, for example 6 to 7 AM, before the first shift.
/**
* Expiration alerts from a "Lots" tab: one row per lot or batch.
* Headers used (any order): Item, Lot, Location, Qty, Expiry date,
* Notify, Status, Sent log. Only Item, Expiry date and Sent log are required.
* Each person gets one email per run listing the lots that are about to
* expire or have expired while still in stock. Qty 0, or a Status such as
* Used up / Discarded, stops a row.
*/
const SHEET_NAME = 'Lots';
const REMIND_DAYS = [60, 30, 7, 0]; // days before the expiry date (0 = the day itself)
const EXPIRED_DAYS = [1, 7]; // days after it, while the lot is still in stock
const DEFAULT_TO = ''; // used when Notify is blank; blank = you
const STOP_STATUS = /^(used up|sold|sold out|discarded|disposed|returned|written off|donated)$/i;
const PREVIEW = true; // true: everything goes to you, nothing is logged
const MAX_EMAILS = 50; // safety cap per run (one email per person)
const SUBJECT = 'Expiring stock: {{Count}} ({{Expired}} expired)';
const INTRO = 'Hi,\n\nThese lots are close to their expiry date or past it and still in stock:';
const OUTRO = 'Use or move the soonest-expiring stock first. When a lot is gone, set Qty to 0 or Status to Used up / Discarded and the alerts stop.';
function sendExpiryAlerts(now) {
const lock = LockService.getDocumentLock();
if (!lock.tryLock(30000)) return; // another run is still going
try {
// A time-driven trigger passes an event object, so only use a real Date.
return alertExpiring_(now instanceof Date ? new Date(now) : new Date());
} finally {
lock.releaseLock();
}
}
function alertExpiring_(now) {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName(SHEET_NAME);
if (!sh) throw new Error(`No tab named ${SHEET_NAME}.`);
const rows = sh.getDataRange().getValues();
const head = rows[0].map((h) => String(h).trim());
const col = (name) => head.indexOf(name);
const c = { item: col('Item'), lot: col('Lot'), where: col('Location'), qty: col('Qty'),
exp: col('Expiry date'), to: col('Notify'), status: col('Status'), log: col('Sent log') };
if ([c.item, c.exp, c.log].includes(-1)) {
throw new Error('Need Item, Expiry date and Sent log columns.');
}
// Count days in the spreadsheet's own time zone (File > Settings),
// so a script project set to another zone can't shift alerts by a day.
const tz = ss.getSpreadsheetTimeZone();
const ymd = (d) => Utilities.formatDate(d, tz, 'yyyy-MM-dd');
const dayNum = (d) => Date.UTC(...ymd(d).split('-').map((x, i) => +x - (i === 1 ? 1 : 0))) / 86400000;
const today = dayNum(now);
const isDate = (v) => v instanceof Date && !isNaN(v);
const EMAIL = /^[^\s@,;]+@[^\s@,;]+\.[^\s@,;]+$/;
const me = Session.getEffectiveUser().getEmail();
// One list of steps: 30 = 30 days before, -7 = 7 days after expiry.
const steps = REMIND_DAYS.concat(EXPIRED_DAYS.map((n) => -n));
const byPerson = {};
let badEmail = 0;
for (let r = 1; r < rows.length; r++) {
const row = rows[r];
const text = (i) => (i === -1 ? '' : String(row[i]).trim());
if (STOP_STATUS.test(text(c.status))) continue;
const qty = c.qty === -1 ? '' : row[c.qty];
if (typeof qty === 'number' && qty <= 0) continue; // used up; blank Qty counts as in stock
const exp = row[c.exp];
if (!isDate(exp) || text(c.item) === '') continue;
const left = dayNum(exp) - today; // negative = expired
// The one step that fits today: no pile of earlier ones after a gap.
// Once a lot has expired, only the EXPIRED_DAYS steps apply.
const hit = steps.filter((s) => left <= s && (left >= 0 || s < 0)).sort((a, b) => a - b)[0];
if (hit === undefined) continue;
const sent = String(row[c.log] || '').split(';').filter(String);
// Keyed to the expiry date: correcting the date restarts the alerts.
const key = `E${ymd(exp)}@${hit}`;
if (sent.includes(key)) continue;
const to = (text(c.to) || DEFAULT_TO || me).toLowerCase();
if (!EMAIL.test(to)) { badEmail++; console.log(`Row ${r + 1}: check the Notify email`); continue; }
const when = left > 1 ? `expires in ${left} days` : left === 1 ? 'expires tomorrow' :
left === 0 ? 'expires today' : left === -1 ? 'EXPIRED yesterday' : `EXPIRED ${-left} days ago`;
const item = {
r: r + 1, left, where: text(c.where),
line: `- ${text(c.item)}` +
(text(c.lot) ? ` (lot ${text(c.lot)})` : '') +
(qty !== '' ? `, qty ${qty}` : '') +
(text(c.where) ? `, ${text(c.where)}` : '') +
`: ${Utilities.formatDate(exp, tz, 'EEE, MMM d, yyyy')} (${when})`,
log: sent.concat(key).slice(-12).join(';'),
};
(byPerson[to] = byPerson[to] || []).push(item);
}
// People with the most urgent lot first, in case the quota runs out.
const groups = Object.keys(byPerson).map((to) => {
const items = byPerson[to].sort((a, b) => a.left - b.left || a.where.localeCompare(b.where) || a.r - b.r);
return { to, items, worst: items[0].left };
}).sort((a, b) => a.worst - b.worst);
let sent = 0;
for (const g of groups) {
if (sent >= MAX_EMAILS || MailApp.getRemainingDailyQuota() < 1) break;
const expired = g.items.filter((i) => i.left < 0).length;
const subject = SUBJECT.replace('{{Count}}', g.items.length + (g.items.length === 1 ? ' lot' : ' lots')).replace('{{Expired}}', expired);
const body = [INTRO, '', ...g.items.map((i) => i.line), '', OUTRO, '', `Sheet: ${ss.getUrl()}`].join('\n');
MailApp.sendEmail({
to: PREVIEW ? me : g.to,
subject: PREVIEW ? `[PREVIEW to ${g.to}] ${subject}` : subject,
body,
});
sent++;
if (!PREVIEW) {
// Log right after each email, so a crash can't cause a repeat.
g.items.forEach((i) => sh.getRange(i.r, c.log + 1).setValue(i.log));
SpreadsheetApp.flush();
}
}
const result = { sent, left: groups.length - sent, badEmail, preview: PREVIEW };
console.log(JSON.stringify(result));
return result;
}
How it behaves:
- One email per person. Each run, everyone with something new gets a single list, most urgent first: “Oat milk 1 L (lot A1), qty 12, Walk-in cooler: Mon, Nov 30, 2026 (expires in 14 days)”. Lots with the same date are grouped by location, so the list reads like a walk through the store room. The person with the most urgent lot is emailed first.
- Before, on and after the date. With the defaults a lot is mentioned 60, 30 and 7 days before, on the day, and 1 and 7 days after if it is still in stock, then the script goes quiet. Change
REMIND_DAYSto suit the shelf life of what you keep (fresh food might use[3, 1, 0]);EXPIRED_DAYS = []turns the after-expiry alerts off. - Gone stops it. Set Qty to 0 or Status to Used up (or Sold, Discarded, Disposed, Returned, Written off, Donated) and that row gets no more email.
- No pile-up. A lot entered late, or after a few days without the trigger, gets only the latest alert that applies, once. An expired lot never gets a “before” alert.
- Correcting a date restarts it. The Sent log is keyed to the expiry date, so if you fix a typo in a date, alerts start again for the new one.
- Safe to rerun. Rows are logged right after each email, a document lock stops two runs overlapping, at most
MAX_EMAILSgo per run, and it stops when your daily Apps Script email quota runs out (100 recipients a day on a personal Gmail account, 1,500 on Google Workspace). Anything left goes on the next run.
Tips
- Add a row when stock arrives. Make it part of receiving: one row per delivery with its expiry date, before it goes on the shelf. A Google Form that writes to the sheet works if several people receive deliveries; copy its answers into Lots with the same headers.
- Keep Qty roughly right. The alerts are only as good as the counts. If nobody updates Qty day to day, at least set it to 0 (or Status to Used up) when the last unit of a lot goes, so the alerts for it stop.
- Split lots by location. If one delivery is spread over two rooms or vans, make it two rows with their own Qty and Location, so each alert says where to look.
- Check the time zone. The script counts days in the spreadsheet's time zone (File › Settings › Time zone), and the trigger fires in the Apps Script project's time zone (Project Settings). Set both to where the stock is.
- Ownership. The trigger runs as whoever created it, and the emails come from that account. Set it up from a shared operations account, not one person's, so it keeps working when they leave.
- Rules come first. For medicines, vaccines, food safety and hazardous materials, your regulator's and the manufacturer's rules on storage, labelling and disposal apply. Treat the sheet as a reminder, not as your compliance record.
- Need a document per lot, like a shelf label or a disposal record filled from the row? See a PDF or Google Doc for each row.
See SheetReminders
Short on time? Watch the 50-second version
Related Google Sheets guides
- How to generate a PDF or Google Doc for each row in Google Sheets
- Find and remove duplicates in Google Sheets
- Compare two columns or two sheets for duplicates
- Find case-insensitive and fuzzy duplicates in Google Sheets
- Best Autocrat alternatives for mail merge to PDF and Docs
- Make invoices or certificates from Google Sheets rows
- Create sales quotes or estimates from Google Sheets
- Generate receipts from Google Sheets rows
- Create purchase orders from Google Sheets
- Make packing slips from Google Sheets orders
- Generate a PDF certificate from a Google Form response
- Issue numbered training completion certificates with expiry dates
- Make a PDF progress report for each student
- Generate offer letters from a Google Sheets hiring tracker
- Generate contracts and agreements from a Google Docs template
- Make work orders for service jobs from Google Sheets
- Email each row’s PDF as an attachment
- Automatic email reminders from a date column
- Contract renewal and expiration alerts from Google Sheets
- Track certificate of insurance (COI) expirations in Google Sheets
- Track employee license and certification expirations
- Track equipment and vehicle maintenance with reminders
- Equipment sign-out sheet with due-back and overdue reminders
- Track warranty expiration dates with reminders
- Birthday and work anniversary reminders from Google Sheets
- Rent due and lease renewal reminders from Google Sheets
- Send invoice payment reminders from Google Sheets
- Highlight overdue tasks and send email reminders
- Follow-up reminders for leads, clients and candidates
- Membership renewal reminders for clubs and associations
- Appointment reminder emails for clients
- Probation and performance review reminders for managers
- Inventory expiration dates with email alerts
- Domain and SSL certificate renewal reminders
- Name badges and place cards from a guest list
- Vehicle registration, inspection and insurance reminders
- Event sign-in sheets and table seating lists
- Pet vaccination expiry reminders for owners
- Customer account statements with aging
- Subscription tracker with renewal and free-trial reminders
- Mailing labels: one per household, clean addresses
- Volunteer shifts: open slots, reminders and rosters
- Year-end donor giving statements, one PDF per donor
- Volunteer hours verification letters, one PDF per request
- Instrument calibration due dates with email reminders
- Pay stubs from a payroll sheet, one PDF per employee
- Gift certificates with codes, balances and a redemption log
- Bill due dates: mark paid, 30-day totals and reminders
- Grant deadlines: LOIs, reports, owners and reminders
- Passport expiry: trips, the 6-month rule and renewal reminders
- Class rosters: one PDF per class, A–Z, with seat counts
- Insurance renewals: premium changes and reminders
- Onboarding checklists: tasks from start dates, owner reminders
- Raffle tickets: numbered stubs, seller books, sales tracker
- SheetWeave vs Autocrat
- SheetWeave vs Document Studio
- SheetWeave vs RowDocs
Instructions refer to Google Sheets and Apps Script as they worked on November 14, 2026. Not affiliated with Google or any other vendor named here. Google Sheets and Google Docs are trademarks of Google LLC. Features change, so verify in your own account. This is not food safety, pharmacy or regulatory advice. Questions or corrections: hello@loomwise.app.