Why your dates are off by a day — and how to fix it

The user picked 11 August. The database holds 11 August. The screen says the 10th.
Nothing was lost and nothing is broken. Somewhere along the way a "calendar day" was turned into a "moment in time" — and a moment in time happily lands in yesterday in someone else's zone. Here are the three places it happens, in order of frequency.
Cause 1: the string "2026-08-11" is read as UTC
The most common and the least visible. This line:
new Date("2026-08-11")
gives you midnight in UTC, not where you are. In Berlin that's 02:00 on the 11th (you got away with it), in New York it's 20:00 on 10 August. Show that day to a user and you've shown them yesterday.
Now the sneaky part. Add a time, and the rule flips:
new Date("2026-08-11") // midnight UTC
new Date("2026-08-11T00:00") // midnight local time
Same date, the only difference is whether a time is present — and the result shifts by your whole offset. This isn't a browser quirk; it's in the language spec: a date-only string counts as UTC, a date-time string without a zone counts as local.
How to check. Open the console and see what your string actually becomes:
new Date("2026-08-11").toString()
You'll see the real moment in your own zone, and whether it drifted.
How to fix. If what you need is a calendar day — a birthday, a deadline, a booking date — don't turn it into a Date at all. Store and display it as the string 2026-08-11, slice it by characters, compare it as text. And if you do need a date object, build it explicitly from parts: new Date(2026, 7, 11) — remembering that months here start at zero, so August is 7.
Cause 2: the server lives in UTC, you don't
Almost every host runs in UTC by default. Locally you're in Berlin and everything looks right. In production the gap is two hours, so anything happening after 22:00 local gets written with yesterday's date. The "today" report quietly under-counts the evening.
This is a classic member of the "works locally, breaks in production" family: same code, different environment.
How to check. Run date on the server and SELECT now(); in the database. In your app, log the zone it thinks it's in:
console.log(Intl.DateTimeFormat().resolvedOptions().timeZone);
How to fix. Don't "set the server to Berlin" — that only gets worse when a second server or a second user appears. Do the opposite: keep the server and database in UTC always, and apply the user's zone once, at render time, naming it explicitly:
new Intl.DateTimeFormat("en-GB", { timeZone: "Europe/Berlin" }).format(d);
Cause 3: toISOString() cuts the day in UTC
A very popular move — save the chosen date like this:
const day = d.toISOString().slice(0, 10); // "2026-08-11"
It looks tidy and breaks in exactly the same places. toISOString() always converts the moment to UTC first, and only then do you take the first ten characters. For anyone east of Greenwich, late in the evening that yields tomorrow; for anyone west, yesterday.
How to check. Set your system clock to 23:30 and try again. Or just print the value next to its toISOString() and compare with your eyes.
How to fix. Build the day from local parts instead of the ISO string:
const day = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
Bonus cause: daylight saving time
If the shift only appears "from some month onwards", switching to summer time is your culprit. The gap between zones isn't a constant: in half the world it changes twice a year.
That's exactly why you can't store an offset (+02:00) instead of a zone name: an offset is only correct on a specific date. Store Europe/Berlin, not +02:00, and let the library work out what the time was on the day in question.
The rule that closes all three
Separate two different things in your head, and most date bugs fall away on their own:
- A moment in time — "when it happened". An order was created, a user signed in. Store it in UTC:
timestamptzin the database or a unix timestamp. Add a time zone only when displaying. - A calendar day — "what the calendar says". A birthday, a concert date, a reporting period. That's not a moment in time, it's text. Store it as
dateor the stringYYYY-MM-DDand never run it through a date object.
Is storing a date as a string acceptable?
For a calendar day, yes — that's the correct option: a string has no time zone, so there's nothing to shift. For a moment in time, no — there you need a proper type with a zone, or you lose the ability to compare events.
Why does the database hold one value and the screen show another?
Postgres stores a timestamptz in UTC and returns it in the current connection's zone. Your app then adds its own zone while formatting. Two conversions, two chances to drift — which is why you keep everything in UTC until the moment of display.
The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.





