pandas.to_datetime

pandas 3.1.1 · General functions · function

Parse input as datetimes. Use format for a known layout, utc=True to normalize to UTC and errors="coerce" to mark invalid values as NaT.

Call syntax

pd.to_datetime(…) Full signature
pd.to_datetime(
    arg,
    errors='raise',
    dayfirst=False,
    yearfirst=False,
    utc=False,
    format=None,
    exact=…,
    unit=None,
    origin='unix',
    cache=True,
)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
arg Required
Positional or keyword
int, float, str, datetime, list, tuple, 1-d array, Series, DataFrame/dict-like

Pass date text, a numeric epoch value, a datetime, an array-like, or a table with date fields.

errors Optional
Positional or keyword
Default 'raise'
{'raise', 'coerce'}

Choose "raise" to reject invalid dates or "coerce" to turn them into NaT.

dayfirst Optional
Positional or keyword
Default False
bool

Prefer the day before the month when interpreting ambiguous date text.

yearfirst Optional
Positional or keyword
Default False
bool
utc Optional
Positional or keyword
Default False
bool

True localizes naive values to UTC and converts timezone-aware values to UTC.

format Optional
Positional or keyword
Default None
str

Use a strftime-style pattern for a known layout, "ISO8601" for ISO text, or "mixed" to infer per value.

exact Optional
Positional or keyword
bool

Choose whether the parser requires an exact format match.

unit Optional
Positional or keyword
Default None
str

Specify the time unit represented by each number or required by the result.

origin Optional
Positional or keyword
Default 'unix'
scalar

Choose the reference timestamp or origin from which a numeric time or bin is measured.

cache Optional
Positional or keyword
Default True
bool

Reuse the conversion of repeated date strings where pandas can apply the cache.

Returns

datetime