DEV Community

Cover image for My XLSX converter shipped dates as five-digit numbers — Excel stores dates as serials, not values
InApp
InApp

Posted on Originally published at imapp.blogspot.com

My XLSX converter shipped dates as five-digit numbers — Excel stores dates as serials, not values

A timesheet workbook came through my converter and the Markdown table was nearly perfect — except the Date column read 45291, 45292, 45293. The human's sheet showed "12/31/2023, 01/01/2024, 01/02/2024". Mine showed numbers an agent can't reason about.

Excel doesn't store dates at all. Every date is a serial number: days elapsed since 1900-01-01, with times as the fractional part. 45366.5 is noon on 2024-03-15. The human-readable date is purely the cell's number format string — yyyy-mm-dd, [$-409]mmmm d, yyyy, whatever the author picked. Read the raw value from the XML and you get the serial.

The trap has teeth beyond dates:

  • A cell holding 0.0833 with format [h]:mm is "2:00" — a duration in an hours-worked column. A naive converter dumps 0.0833 into the table. Rounds it, even.
  • The same workbook may use the 1904 date system (old Mac files), which shifts every serial by exactly 1,462 days. Convert blind and every date drifts four years.
  • Excel inherits the Lotus 1-2-3 leap-year bug: serials below 60 are off by one day versus real dates. Irrelevant in 2025, but it's in the spec.

The fix I settled on: inspect each cell's format code before deciding anything. Format contains d/m/y tokens → emit ISO 8601 (2024-03-15), unambiguous regardless of locale. Contains h/m/s → render HH:MM or an ISO duration. Otherwise keep the number as-is, because with format 0.00 that 0.0833 really is a measurement, not a time.

I ended up packaging that logic into my XLSX-to-Markdown API (https://x402.freeq.one/tools/xlsx_to_markdown.html) — the same timesheet that shipped raw serials now yields "date": "2024-03-15" in both the Markdown table and the JSON rows.

The broader lesson: spreadsheets are a display format pretending to be a data format. Everything you see on screen is a rendering decision; the file itself just stores numbers and format strings, some of them decisions made in 1987 for Lotus compatibility.

Top comments (0)