DateTime Objects

Various date and time objects are supplied by thedatetime module.Before using any of these functions, the header filedatetime.h must beincluded in your source (note that this is not included byPython.h),and the macroPyDateTime_IMPORT must be invoked, usually as part ofthe module initialisation function. The macro puts a pointer to a C structureinto a static variable,PyDateTimeAPI, that is used by the followingmacros.

Macro for access to the UTC singleton:

PyObject*PyDateTime_TimeZone_UTC

Returns the time zone singleton representing UTC, the same object asdatetime.timezone.utc.

New in version 3.7.

Type-check macros:

intPyDate_Check(PyObject *ob)

Return true ifob is of typePyDateTime_DateType or a subtype ofPyDateTime_DateType.ob must not beNULL.

intPyDate_CheckExact(PyObject *ob)

Return true ifob is of typePyDateTime_DateType.ob must not beNULL.

intPyDateTime_Check(PyObject *ob)

Return true ifob is of typePyDateTime_DateTimeType or a subtype ofPyDateTime_DateTimeType.ob must not beNULL.

intPyDateTime_CheckExact(PyObject *ob)

Return true ifob is of typePyDateTime_DateTimeType.ob must notbeNULL.

intPyTime_Check(PyObject *ob)

Return true ifob is of typePyDateTime_TimeType or a subtype ofPyDateTime_TimeType.ob must not beNULL.

intPyTime_CheckExact(PyObject *ob)

Return true ifob is of typePyDateTime_TimeType.ob must not beNULL.

intPyDelta_Check(PyObject *ob)

Return true ifob is of typePyDateTime_DeltaType or a subtype ofPyDateTime_DeltaType.ob must not beNULL.

intPyDelta_CheckExact(PyObject *ob)

Return true ifob is of typePyDateTime_DeltaType.ob must not beNULL.

intPyTZInfo_Check(PyObject *ob)

Return true ifob is of typePyDateTime_TZInfoType or a subtype ofPyDateTime_TZInfoType.ob must not beNULL.

intPyTZInfo_CheckExact(PyObject *ob)

Return true ifob is of typePyDateTime_TZInfoType.ob must not beNULL.

Macros to create objects:

PyObject*PyDate_FromDate(int year, int month, int day)
Return value: New reference.

Return adatetime.date object with the specified year, month and day.

PyObject*PyDateTime_FromDateAndTime(int year, int month, int day, int hour, int minute, int second, int usecond)
Return value: New reference.

Return adatetime.datetime object with the specified year, month, day, hour,minute, second and microsecond.

PyObject*PyDateTime_FromDateAndTimeAndFold(int year, int month, int day, int hour, int minute, int second, int usecond, int fold)
Return value: New reference.

Return adatetime.datetime object with the specified year, month, day, hour,minute, second, microsecond and fold.

New in version 3.6.

PyObject*PyTime_FromTime(int hour, int minute, int second, int usecond)
Return value: New reference.

Return adatetime.time object with the specified hour, minute, second andmicrosecond.

PyObject*PyTime_FromTimeAndFold(int hour, int minute, int second, int usecond, int fold)
Return value: New reference.

Return adatetime.time object with the specified hour, minute, second,microsecond and fold.

New in version 3.6.

PyObject*PyDelta_FromDSU(int days, int seconds, int useconds)
Return value: New reference.

Return adatetime.timedelta object representing the given numberof days, seconds and microseconds. Normalization is performed so that theresulting number of microseconds and seconds lie in the ranges documented fordatetime.timedelta objects.

PyObject*PyTimeZone_FromOffset(PyDateTime_DeltaType* offset)
Return value: New reference.

Return adatetime.timezone object with an unnamed fixed offsetrepresented by theoffset argument.

New in version 3.7.

PyObject*PyTimeZone_FromOffsetAndName(PyDateTime_DeltaType* offset, PyUnicode* name)
Return value: New reference.

Return adatetime.timezone object with a fixed offset representedby theoffset argument and with tznamename.

New in version 3.7.

Macros to extract fields from date objects. The argument must be an instance ofPyDateTime_Date, including subclasses (such asPyDateTime_DateTime). The argument must not beNULL, and the type isnot checked:

intPyDateTime_GET_YEAR(PyDateTime_Date *o)

Return the year, as a positive int.

intPyDateTime_GET_MONTH(PyDateTime_Date *o)

Return the month, as an int from 1 through 12.

intPyDateTime_GET_DAY(PyDateTime_Date *o)

Return the day, as an int from 1 through 31.

Macros to extract fields from datetime objects. The argument must be aninstance ofPyDateTime_DateTime, including subclasses. The argumentmust not beNULL, and the type is not checked:

intPyDateTime_DATE_GET_HOUR(PyDateTime_DateTime *o)

Return the hour, as an int from 0 through 23.

intPyDateTime_DATE_GET_MINUTE(PyDateTime_DateTime *o)

Return the minute, as an int from 0 through 59.

intPyDateTime_DATE_GET_SECOND(PyDateTime_DateTime *o)

Return the second, as an int from 0 through 59.

intPyDateTime_DATE_GET_MICROSECOND(PyDateTime_DateTime *o)

Return the microsecond, as an int from 0 through 999999.

intPyDateTime_DATE_GET_FOLD(PyDateTime_DateTime *o)

Return the fold, as an int from 0 through 1.

New in version 3.6.

Macros to extract fields from time objects. The argument must be an instance ofPyDateTime_Time, including subclasses. The argument must not beNULL,and the type is not checked:

intPyDateTime_TIME_GET_HOUR(PyDateTime_Time *o)

Return the hour, as an int from 0 through 23.

intPyDateTime_TIME_GET_MINUTE(PyDateTime_Time *o)

Return the minute, as an int from 0 through 59.

intPyDateTime_TIME_GET_SECOND(PyDateTime_Time *o)

Return the second, as an int from 0 through 59.

intPyDateTime_TIME_GET_MICROSECOND(PyDateTime_Time *o)

Return the microsecond, as an int from 0 through 999999.

intPyDateTime_TIME_GET_FOLD(PyDateTime_Time *o)

Return the fold, as an int from 0 through 1.

New in version 3.6.

Macros to extract fields from time delta objects. The argument must be aninstance ofPyDateTime_Delta, including subclasses. The argument mustnot beNULL, and the type is not checked:

intPyDateTime_DELTA_GET_DAYS(PyDateTime_Delta *o)

Return the number of days, as an int from -999999999 to 999999999.

New in version 3.3.

intPyDateTime_DELTA_GET_SECONDS(PyDateTime_Delta *o)

Return the number of seconds, as an int from 0 through 86399.

New in version 3.3.

intPyDateTime_DELTA_GET_MICROSECONDS(PyDateTime_Delta *o)

Return the number of microseconds, as an int from 0 through 999999.

New in version 3.3.

Macros for the convenience of modules implementing the DB API:

PyObject*PyDateTime_FromTimestamp(PyObject *args)
Return value: New reference.

Create and return a newdatetime.datetime object given an argumenttuple suitable for passing todatetime.datetime.fromtimestamp().

PyObject*PyDate_FromTimestamp(PyObject *args)
Return value: New reference.

Create and return a newdatetime.date object given an argumenttuple suitable for passing todatetime.date.fromtimestamp().