pandas.Timestamp.to_pydatetime#

Timestamp.to_pydatetime(warn=True)#

Convert a Timestamp object to a native Python datetime object.

This method is useful for when you need to utilize a pandas Timestamp object in contexts where native Python datetime objects are expected or required. The conversion discards the nanoseconds component, and a warning can be issued in such cases if desired.

Parameters:
warnbool, default True

If True, issues a warning when the timestamp includes nonzero nanoseconds, as these will be discarded during the conversion.

Returns:
datetime.datetime or NaT

Returns a datetime.datetime object representing the timestamp, with year, month, day, hour, minute, second, and microsecond components. If the timestamp is NaT (Not a Time), returns NaT.

See also

datetime.datetime

The standard Python datetime class that this method returns.

Timestamp.timestamp

Convert a Timestamp object to POSIX timestamp.

Timestamp.to_datetime64

Convert a Timestamp object to numpy.datetime64.

Examples

>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548')
>>> ts.to_pydatetime()
datetime.datetime(2020, 3, 14, 15, 32, 52, 192548)

Analogous for pd.NaT:

>>> pd.NaT.to_pydatetime()
NaT