7.5.12 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 include by Python.h), and macro PyDateTime_IMPORT()
must be invoked. The macro arranges to put a pointer to a C structure
in a static variable PyDateTimeAPI
, which is used by the following
macros.
Type-check macros:
- Return true if ob is of type PyDateTime_DateType or a subtype of PyDateTime_DateType. ob must not be NULL. New in version 2.4.
- Return true if ob is of type PyDateTime_DateType. ob must not be NULL. New in version 2.4.
- Return true if ob is of type PyDateTime_DateTimeType or a subtype of PyDateTime_DateTimeType. ob must not be NULL. New in version 2.4.
- Return true if ob is of type PyDateTime_DateTimeType. ob must not be NULL. New in version 2.4.
- Return true if ob is of type PyDateTime_TimeType or a subtype of PyDateTime_TimeType. ob must not be NULL. New in version 2.4.
- Return true if ob is of type PyDateTime_TimeType. ob must not be NULL. New in version 2.4.
- Return true if ob is of type PyDateTime_DeltaType or a subtype of PyDateTime_DeltaType. ob must not be NULL. New in version 2.4.
- Return true if ob is of type PyDateTime_DeltaType. ob must not be NULL. New in version 2.4.
- Return true if ob is of type PyDateTime_TZInfoType or a subtype of PyDateTime_TZInfoType. ob must not be NULL. New in version 2.4.
- Return true if ob is of type PyDateTime_TZInfoType. ob must not be NULL. New in version 2.4.
Macros to create objects:
-
Return a
datetime.date
object with the specified year, month and day. New in version 2.4.
-
Return a
datetime.datetime
object with the specified year, month, day, hour, minute, second and microsecond. New in version 2.4.
-
Return a
datetime.time
object with the specified hour, minute, second and microsecond. New in version 2.4.
-
Return a
datetime.timedelta
object representing the given number of days, seconds and microseconds. Normalization is performed so that the resulting number of microseconds and seconds lie in the ranges documented fordatetime.timedelta
objects. New in version 2.4.
Macros to extract fields from date objects. The argument must be an instance of PyDateTime_Date, including subclasses (such as PyDateTime_DateTime). The argument must not be NULL, and the type is not checked:
- Return the year, as a positive int. New in version 2.4.
- Return the month, as an int from 1 through 12. New in version 2.4.
- Return the day, as an int from 1 through 31. New in version 2.4.
Macros to extract fields from datetime objects. The argument must be an instance of PyDateTime_DateTime, including subclasses. The argument must not be NULL, and the type is not checked:
- Return the hour, as an int from 0 through 23. New in version 2.4.
- Return the minute, as an int from 0 through 59. New in version 2.4.
- Return the second, as an int from 0 through 59. New in version 2.4.
- Return the microsecond, as an int from 0 through 999999. New in version 2.4.
Macros to extract fields from time objects. The argument must be an instance of PyDateTime_Time, including subclasses. The argument must not be NULL, and the type is not checked:
- Return the hour, as an int from 0 through 23. New in version 2.4.
- Return the minute, as an int from 0 through 59. New in version 2.4.
- Return the second, as an int from 0 through 59. New in version 2.4.
- Return the microsecond, as an int from 0 through 999999. New in version 2.4.
Macros for the convenience of modules implementing the DB API:
-
Create and return a new
datetime.datetime
object given an argument tuple suitable for passing todatetime.datetime.fromtimestamp()
. New in version 2.4.
-
Create and return a new
datetime.date
object given an argument tuple suitable for passing todatetime.date.fromtimestamp()
. New in version 2.4.