๐Ÿ€Zerve chosen as NCAA's Agentic Data Platform for 2026 Hackathonยท๐ŸงฎMeet the Zerve Team at Data Decoded Londonยท๐Ÿ“ˆWe're hiring โ€” awesome new roles just gone live!
Back
Pandas

OutOfBoundsDatetime: Out of bounds nanosecond timestamp - How to Fix it

Answer

This error means your date is outside pandas' supported range (1677 to 2262). Fix it by using errors='coerce' to convert invalid dates to NaT, or switch to object dtype if you need to preserve dates outside that range.

Why This Happens

Pandas stores datetimes as nanoseconds since 1970, using a 64-bit integer. This limits the range to approximately 1677-09-21 to 2262-04-11. Dates outside this range โ€” like year 9999 for "never expires" or historical dates before 1677 โ€” can't be represented and raise this error.

Solution

The rule: if your data might contain dates before 1677 or after 2262, always use errors='coerce' or keep as strings.

import pandas as pd

# โŒ Problematic: date outside pandas range
df = pd.DataFrame({'date': ['2020-01-01', '9999-12-31']})
df['date'] = pd.to_datetime(df['date'])
# OutOfBoundsDatetime: Out of bounds nanosecond timestamp

# โœ… Fixed: coerce invalid dates to NaT
df['date'] = pd.to_datetime(df['date'], errors='coerce')
# 9999-12-31 becomes NaT

# โœ… Fixed: keep as string if you need the original values
df['date_str'] = df['date'].astype(str)  # preserve for display
df['date_parsed'] = pd.to_datetime(df['date'], errors='coerce')  # parse what you can

# โœ… Alternative: use datetime.datetime for out-of-range dates
from datetime import datetime
# Store as object dtype, handle manually

Better Workflow

Zerve lets you inspect column values inline before parsing, so you can spot outlier dates like 9999-12-31 before they break your datetime conversion.

Better workflow

Related Topics

Decision-grade data work

Explore, analyze and deploy your first project in minutes