Period.datetime#

abstractmethod Period.datetime(ordinal)[source]#

Return the datetime at which the interval with the supplied ordinal starts.

The inverse of ordinal().

Parameters:

ordinal (int) – The integer ordinal, as produced by this same Period’s ordinal()

Return type:

datetime

Returns:

A datetime object marking the first instant of that interval, carrying this Period’s own tzinfo

Raises:

ValueError – If the ordinal maps outside the year range 0001-9999. Ordinals are unbounded integers but datetimes are not, so the extremes of the timeline are unreachable.

Examples

>>> from datetime import datetime
>>> pt1h = Period.of_hours(1)
>>> n = pt1h.ordinal(datetime(2024, 3, 1, 9, 47))
>>> pt1h.datetime(n)
datetime.datetime(2024, 3, 1, 9, 0)
>>> pt1h.datetime(n + 1)
datetime.datetime(2024, 3, 1, 10, 0)