DateTime Objects¶
Various date and time objects are supplied by the datetime module.
Before using any of these functions, the header file datetime.h must be
included in your source (note that this is not included by Python.h),
and the macro PyDateTime_IMPORT must be invoked, usually as part of
the module initialisation function. The macro puts a pointer to a C structure
into a static variable, PyDateTimeAPI, that is used by the following
macros.
-
PyDateTime_IMPORT()¶
Import the datetime C API.
On success, populate the
PyDateTimeAPIpointer. On failure, setPyDateTimeAPItoNULLand set an exception. The caller must check if an error occurred viaPyErr_Occurred():PyDateTime_IMPORT; if (PyErr_Occurred()) { /* cleanup */ }
Warning
This is not compatible with subinterpreters.
-
type PyDateTime_CAPI¶
Structure containing the fields for the datetime C API.
The fields of this structure are private and subject to change.
Do not use this directly; prefer
PyDateTime_*APIs instead.
-
PyDateTime_CAPI *PyDateTimeAPI¶
Dynamically allocated object containing the datetime C API.
This variable is only available once
PyDateTime_IMPORTsucceeds.
-
type PyDateTime_Delta¶
This subtype of
PyObjectrepresents the difference between two datetime values.
-
PyTypeObject PyDateTime_DateType¶
This instance of
PyTypeObjectrepresents the Python date type; it is the same object asdatetime.datein the Python layer.
-
PyTypeObject PyDateTime_DateTimeType¶
This instance of
PyTypeObjectrepresents the Python datetime type; it is the same object asdatetime.datetimein the Python layer.
-
PyTypeObject PyDateTime_TimeType¶
This instance of
PyTypeObjectrepresents the Python time type; it is the same object asdatetime.timein the Python layer.
-
PyTypeObject PyDateTime_DeltaType¶
This instance of
PyTypeObjectrepresents the Python type for the difference between two datetime values; it is the same object asdatetime.timedeltain the Python layer.