I have opinions about timestamps. Strong opinions. The kind that get me disinvited from parties.
Here’s my hill: if you’re storing market data, writing backtests, or doing anything with financial time series, ISO 8601 isn’t optional—it’s the only sane choice. I’ve debugged too many off-by-one-day errors caused by MM/DD/YYYY vs DD/MM/YYYY confusion in trade files. I’ve watched a backtest produce nonsense because someone stored timestamps without timezone info and the parser guessed wrong.
ISO 8601 fixes this. It’s unambiguous, it sorts lexicographically (your filenames will thank you), and it handles everything from “market open on January 15th” to “repeat this rebalancing every third Friday.”
Most developers know YYYY-MM-DD. But ISO 8601 goes deeper than you’d expect. Let’s explore:
The Basics (That You Probably Know)
- 2024-10-14 — The canonical date format. Sorts correctly, no ambiguity.
- 20241014 — Compact form for filenames:
trades_20241014.csvsorts chronologically in any file browser. - 2024-10-14T09:30:00 — Market open in New York. The
Tseparator is ugly but unambiguous. - 2024-10-14T09:30:00.123456 — Microsecond precision for tick data. Yes, you need it.
- 2024-10-14T13:30:00Z — The
Zmeans UTC. If you’re storing market data without explicit timezones, store UTC and convert on display. Trust me. - 2024-10-14T09:30:00-04:00 — Eastern Daylight Time. The offset makes it explicit—no guessing whether we’re in DST.
Weeks and Ordinal Days (Surprisingly Useful)
- 2024-W42 — Week 42 of 2024. Handy for weekly rebalancing schedules or P&L reporting.
- 2024-W42-5 — Friday of week 42. Options expiration is typically the third Friday—ISO week-day format makes this easy to compute.
- 2024-288 — The 288th day of 2024. I use ordinal dates for partitioning daily data:
ohlcv/2024/288/AAPL.parquet. Clean, sortable, no month boundaries to think about.
Durations (For Lookback Windows and Holding Periods)
- P1Y2M3DT4H5M6S — One year, two months, three days, four hours, five minutes, six seconds. The
Pmeans “period.” - P21D — 21-day lookback window for a moving average.
- PT6H30M — Six and a half hours. Trading session length, perhaps.
- P1M — One month holding period. ISO 8601 handles the variable-length-month problem so you don’t have to.
Uncertainty (Yes, ISO 8601 Has This)
Historical data isn’t always clean. Sometimes you know the trade happened “sometime in Q2” but not exactly when.
- 2024-06-05? — Questionable date. Maybe June 5th, maybe not.
- 2024-06-05~ — Approximate. Close to June 5th.
- 2024-06% — Sometime in June 2024. Useful for corporate actions with fuzzy announcement dates.
I rarely use these in production systems, but they’re handy for data annotation when you’re cleaning historical records.
Recurring Intervals (For Scheduled Jobs)
- R/2024-01-01T09:30:00-05:00/P1D — Repeat indefinitely, starting January 1st at market open, every day. Your daily data ingestion job.
- R52/2024-01-05T16:00:00-05:00/P1W — Repeat 52 times, starting first Friday at market close, weekly. Your end-of-week rebalancing.
- R12/2024-01-31/P1M — Repeat 12 times, monthly. End-of-month NAV calculations.
One format, parseable by any ISO 8601 library. No custom cron syntax to debug.
The Actual Ode (Because I Promised)
Look, I titled this “An Ode to ISO 8601” and I’m committed to the bit. Below is some whimsy I generated with Claude. It’s silly. It rhymes (mostly). It covers the formats. Read it aloud at your next standup to establish dominance.
Oh, ISO 8601, you chronological delight, Bringing order to timestamps, both day and night. No more
12/10/24—is that October or December? With you,2024-10-12is clear to every member!
A Date to Remember
2024-09-04, oh how you shine!
Year, month, and day, all in a line.
No confusion here, it’s crystal clear,
September 4th, 2024, my dear.
But wait! You’re so flexible,
Your basic format is quite collectible:20240904, all smooshed together,
For when hyphens are light as a feather.
Time Waits for No One
But dates alone? That’s just the start,
Let’s add some time, and make it smart:2024-09-04T15:30:00
Hour, minute, second - precision’s your vow!
For those who like their time more compact,
153000is equally exact.
But what about fractions, you might ask?2024-09-04T15:30:00.5- decimal seconds, what a task!
Zoning Out
“But wait,” you cry, “What time zone is that?”
ISO 8601 says, “I’ve got you, stat!”2024-09-04T15:30:00+02:00
Two hours ahead of UTC, now you know!
For UTC itself, just use a Z,
2024-09-04T13:30:00Z
“Zulu time,” they call it, how fancy!
No offset needed, it’s UTC, you see?
Weeks and Ordinal Dates
But some folks like to count their weeks,
ISO 8601 has what everyone seeks:2024-W36-3is our special day,
The 3rd day of the 36th week, hooray!
Ordinal dates, now there’s a treat,
2024-248is oh so sweet.
The 248th day of the year, my friend,
A format that’ll make your head spin!
Intervals
Need to express a range of time?
ISO 8601 does it with rhyme:2024-09-04T13:30:00Z/2024-09-05T02:15:00Z
From start to finish, it’s all in the zone.
Duration’s another trick up its sleeve,
P1Y2M3DT4H5M6S, would you believe?
One year, two months, three days, they say,
Plus four hours, five minutes, six seconds - okay!
For the Developers Among Us
Now, for you coders with curious minds,
Here are some formats to tickle your rinds:
Repeating Intervals
R5/2024-09-04T09:00:00Z/PT2H30M
Repeat five times, starting today at nine,
Every two hours and thirty minutes, feeling fine!
Uncertain or Approximate Dates
2024-09-04?- Maybe it’s this day2024-09~04- September-ish, we’d say2024-09-04%- This date’s approximate, okay?
Significant Digits
2024-09-04S3- Year to day, that’s all we know2024-09-04S6- Precise to the minute, oh how it shows!
Date Accuracy
2024-09-04:02- Give or take 2 days, my friend2024-09-04:05:01- 5 days and 1 hour, at either end
Weeks and Ordinal Dates: The Road Less Traveled
But some folks like to count their weeks,
ISO 8601 has what everyone seeks:2024-W36is our current week,
A format that’s both strong and sleek.
Want to get more specific? No need to be meek,
2024-W36-3is our special day of the week.
The 3rd day of the 36th week, hooray!
Wednesday, September 4th, hip-hip hurray!
For those who love their weeks concise,
2024W36and2024W363are also nice.
No hyphens here, just numbers tight,
For when every character’s a delight.
Remember, the week starts on a Monday,
ISO says it’s the only way!
So2024-W36-1was September 2nd, you see?
And2024-W36-7is the Sunday, whoopee!
Ordinal dates, now there’s a treat,
2024-248is oh so sweet.
The 248th day of the year, my friend,
A format that’ll make your head spin!
Day of the Year: Counting Up the Calendar
Now let’s talk ordinal dates, a numerical delight,
Counting days of the year, from New Year’s night.2024-248is our current day so fine,
The 248th day of 2024, right on time!
In this compact format, so neat and trim,
We see the year, then days - no need to skim.
No months to fuss with, just a simple count,
From 001 to 365 (or 366), the days we surmount.
For 2024, a leap year of note,
We’ve got an extra day to promote:2024-366will be our grand finale,
December 31st, ending the year merrily.
Some more examples, to make it clear:
2024-001is January 1st, Happy New Year!2024-032is February 1st, don’t you know,
And2024-060is February 29th, leap day’s show!
For non-leap years, adjust your view,
2025-365will be the year-end cue.
It’s simple, it’s clear, it’s ordinal perfection,
ISO 8601’s day-counting section!
This format’s handy for many a reason,
Calculating days or tracking the season.
In programming or data, it’s often preferred,
For date math that’s simple, no errors incurred.
So next time you’re asked, “What day is today?”
You can say, “It’s2024-248!” in a nonchalant way.
Watch as they ponder, their brows slightly furrowed,
Then explain ISO’s system, leave them thoroughly wowed!
In Conclusion: A Toast to ISO 8601
So here’s to you, ISO 8601,
A standard that makes our lives great!
From basic dates to complex time,
You handle it all, so sublime.
You bring order to the chaos of dates,
Across borders and timezones, you’re first-rate.
No moreMM/DDorDD/MMconfusion,
With you, there’s only one conclusion:
YYYY-MM-DDis the way to go,
For dates that everyone can know.
So let’s raise a glass to this standard so fine,
ISO 8601, you’re simply divine!