Negative timestamps and dates before 1970

Time did not start in 1970. Instants before the epoch are simply negative numbers, and most modern systems handle them, with a few well-known exceptions.

How it works

The count runs backwards from zero in the same units:

TimestampUTC
01970-01-01T00:00:00Z
-11969-12-31T23:59:59Z
-864001969-12-31T00:00:00Z
-141829401969-07-20T20:17:40Z (Apollo 11 lands on the Moon)
-21474836481901-12-13T20:45:52Z (the lowest signed 32-bit value)
-22089888001900-01-01T00:00:00Z (start of 1900)
-621355968000001-01-01T00:00:00Z (start of year 1)

Dates this far back are computed on the proleptic Gregorian calendar, meaning today's calendar rules extended backwards, even for years before the calendar was introduced. Historical dates recorded in the Julian calendar need converting separately.

What supports them

SystemNegative timestamps
JavaScriptYes. new Date(-1000).toISOString() is 1969-12-31T23:59:59.000Z. Range: about 271,821 BC to AD 275,760.
Pythondatetime covers years 1 to 9999, but datetime.fromtimestamp() with a negative value raises OSError on Windows. Use datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(seconds=ts).
Java, Go, Rust (chrono), Ruby, .NETYes. .NET stops at year 1.
PHPYes on 64-bit builds.
GNU dateYes: date -u -d @-86400.
PostgreSQL, SQLiteYes.
MySQLNo. FROM_UNIXTIME() returns NULL for a negative argument, and the TIMESTAMP type starts at 1970-01-01 00:00:01 UTC. Store earlier dates in DATETIME or DATE.
ExcelOnly back to 1900.
32-bit time_tBack to 1901-12-13T20:45:52Z.

The rounding bug

Converting sub-second units to seconds is where negative values go wrong. Integer division in C, Java, C#, Go and Rust, and Math.trunc in JavaScript, round towards zero. For positive numbers that is the same as rounding down. For negative ones it is not:

-1500 ms is 1.5 seconds before the epoch: 1969-12-31T23:59:58.500Z

truncate:  -1500 / 1000  →  -1   →  23:59:59   wrong second
floor:     floor(-1.5)   →  -2   →  23:59:58   right second, plus 500 ms

Use a flooring operation: Math.floor in JavaScript, // in Python (which already floors), Math.floorDiv and Math.floorMod in Java, div_euclid and rem_euclid in Rust. The matching remainder must be non-negative, so that seconds plus fraction adds back to the original.

Other things to watch

  • -1 as an error value. C's time() and mktime() return -1 on failure, which is also a valid time, one second before the epoch. Code that checks for it treats that instant as an error.
  • Zero as "not set". Many systems use 0 for a missing time, which is why bugs show up as 1 January 1970, or as 31 December 1969 in time zones west of Greenwich.
  • Validation that rejects negatives. A check such as timestamp > 0 is a reasonable guard for "created at" fields and a bug for birth dates.
  • Time zones before 1970. The time zone database records historical offsets only patchily before 1970, and local mean time before standard zones existed gives odd offsets such as −4:56:02 for New York.

For birth dates and historical dates, a calendar date type or an ISO 8601 string such as 1955-03-12 is a better fit than a timestamp: there is no instant involved, only a day.

Questions

Can a Unix timestamp be negative?

Yes. Negative values are times before 1970-01-01T00:00:00Z. For example -1 is 1969-12-31T23:59:59Z.

Why does my date show 31 December 1969?

The timestamp is 0 (or missing and treated as 0), displayed in a time zone behind UTC. Midnight UTC on 1 January 1970 is still the evening of 31 December in the Americas.

How do I store a date of birth before 1970?

Use a date type or an ISO 8601 date string such as 1955-03-12. If it must be a number, use a signed 64-bit integer and check that every layer accepts negative values; MySQL TIMESTAMP columns do not.