Skip to content

Storing a Birthday

  • The core functions, which every industry uses.

Storing a Birthday

A user's birthday is March 15. How do you store it so it always means March 15, no matter where the user travels?

The naive approach

// The naive approach: store as a full datetime in UTC
const birthday = new Date("2024-03-15T00:00:00Z");
// In São Paulo that is March 14 at 9 PM — the wrong local date!
console.log(birthday.toLocaleString("en", { timeZone: "America/Sao_Paulo" }));

Watch it break

The naive approach silently produces wrong results — there is no GMT equivalent to demonstrate because the failure is not using GMT.

Why

A birthday is a *calendar date*, not an instant in time. Storing it as a UTC datetime ties it to a specific moment, which shifts when viewed from a different timezone. GMT's plain date functions (`PlainDate`) are timezone-free by design — "2024-03-15" is March 15 everywhere. A birthday is also a month and a day with no year, so there is no year to drift: adding 365 days from "2023-03-15" gives "2024-03-14", because 29 February 2024 falls inside the span. Store `--03-15` and place it in the year you need.

The gmt approach

import { parseMonthDayFromDate, monthDayToDate } from "@northguild/gmt";

const birthday = parseMonthDayFromDate("2024-03-15"); // "--03-15"
monthDayToDate(birthday, 2025); // "2025-03-15" — for any year, no timezone ambiguity

Same widget, working

output 
Accessibility
© 2026 NorthGuild · Licences

Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else: © 2026 NorthGuild, all rights reserved.