8 Various date and time objects are supplied by the :mod:`datetime` module.
9 Before using any of these functions, the header file :file:`datetime.h` must be
10 included in your source (note that this is not included by :file:`Python.h`),
11 and the macro :cfunc:`PyDateTime_IMPORT` must be invoked. The macro puts a
12 pointer to a C structure into a static variable, ``PyDateTimeAPI``, that is
13 used by the following macros.
18 .. cfunction:: int PyDate_Check(PyObject *ob)
20 Return true if *ob* is of type :cdata:`PyDateTime_DateType` or a subtype of
21 :cdata:`PyDateTime_DateType`. *ob* must not be *NULL*.
26 .. cfunction:: int PyDate_CheckExact(PyObject *ob)
28 Return true if *ob* is of type :cdata:`PyDateTime_DateType`. *ob* must not be
34 .. cfunction:: int PyDateTime_Check(PyObject *ob)
36 Return true if *ob* is of type :cdata:`PyDateTime_DateTimeType` or a subtype of
37 :cdata:`PyDateTime_DateTimeType`. *ob* must not be *NULL*.
42 .. cfunction:: int PyDateTime_CheckExact(PyObject *ob)
44 Return true if *ob* is of type :cdata:`PyDateTime_DateTimeType`. *ob* must not
50 .. cfunction:: int PyTime_Check(PyObject *ob)
52 Return true if *ob* is of type :cdata:`PyDateTime_TimeType` or a subtype of
53 :cdata:`PyDateTime_TimeType`. *ob* must not be *NULL*.
58 .. cfunction:: int PyTime_CheckExact(PyObject *ob)
60 Return true if *ob* is of type :cdata:`PyDateTime_TimeType`. *ob* must not be
66 .. cfunction:: int PyDelta_Check(PyObject *ob)
68 Return true if *ob* is of type :cdata:`PyDateTime_DeltaType` or a subtype of
69 :cdata:`PyDateTime_DeltaType`. *ob* must not be *NULL*.
74 .. cfunction:: int PyDelta_CheckExact(PyObject *ob)
76 Return true if *ob* is of type :cdata:`PyDateTime_DeltaType`. *ob* must not be
82 .. cfunction:: int PyTZInfo_Check(PyObject *ob)
84 Return true if *ob* is of type :cdata:`PyDateTime_TZInfoType` or a subtype of
85 :cdata:`PyDateTime_TZInfoType`. *ob* must not be *NULL*.
90 .. cfunction:: int PyTZInfo_CheckExact(PyObject *ob)
92 Return true if *ob* is of type :cdata:`PyDateTime_TZInfoType`. *ob* must not be
97 Macros to create objects:
100 .. cfunction:: PyObject* PyDate_FromDate(int year, int month, int day)
102 Return a ``datetime.date`` object with the specified year, month and day.
104 .. versionadded:: 2.4
107 .. cfunction:: PyObject* PyDateTime_FromDateAndTime(int year, int month, int day, int hour, int minute, int second, int usecond)
109 Return a ``datetime.datetime`` object with the specified year, month, day, hour,
110 minute, second and microsecond.
112 .. versionadded:: 2.4
115 .. cfunction:: PyObject* PyTime_FromTime(int hour, int minute, int second, int usecond)
117 Return a ``datetime.time`` object with the specified hour, minute, second and
120 .. versionadded:: 2.4
123 .. cfunction:: PyObject* PyDelta_FromDSU(int days, int seconds, int useconds)
125 Return a ``datetime.timedelta`` object representing the given number of days,
126 seconds and microseconds. Normalization is performed so that the resulting
127 number of microseconds and seconds lie in the ranges documented for
128 ``datetime.timedelta`` objects.
130 .. versionadded:: 2.4
132 Macros to extract fields from date objects. The argument must be an instance of
133 :cdata:`PyDateTime_Date`, including subclasses (such as
134 :cdata:`PyDateTime_DateTime`). The argument must not be *NULL*, and the type is
138 .. cfunction:: int PyDateTime_GET_YEAR(PyDateTime_Date *o)
140 Return the year, as a positive int.
142 .. versionadded:: 2.4
145 .. cfunction:: int PyDateTime_GET_MONTH(PyDateTime_Date *o)
147 Return the month, as an int from 1 through 12.
149 .. versionadded:: 2.4
152 .. cfunction:: int PyDateTime_GET_DAY(PyDateTime_Date *o)
154 Return the day, as an int from 1 through 31.
156 .. versionadded:: 2.4
158 Macros to extract fields from datetime objects. The argument must be an
159 instance of :cdata:`PyDateTime_DateTime`, including subclasses. The argument
160 must not be *NULL*, and the type is not checked:
163 .. cfunction:: int PyDateTime_DATE_GET_HOUR(PyDateTime_DateTime *o)
165 Return the hour, as an int from 0 through 23.
167 .. versionadded:: 2.4
170 .. cfunction:: int PyDateTime_DATE_GET_MINUTE(PyDateTime_DateTime *o)
172 Return the minute, as an int from 0 through 59.
174 .. versionadded:: 2.4
177 .. cfunction:: int PyDateTime_DATE_GET_SECOND(PyDateTime_DateTime *o)
179 Return the second, as an int from 0 through 59.
181 .. versionadded:: 2.4
184 .. cfunction:: int PyDateTime_DATE_GET_MICROSECOND(PyDateTime_DateTime *o)
186 Return the microsecond, as an int from 0 through 999999.
188 .. versionadded:: 2.4
190 Macros to extract fields from time objects. The argument must be an instance of
191 :cdata:`PyDateTime_Time`, including subclasses. The argument must not be *NULL*,
192 and the type is not checked:
195 .. cfunction:: int PyDateTime_TIME_GET_HOUR(PyDateTime_Time *o)
197 Return the hour, as an int from 0 through 23.
199 .. versionadded:: 2.4
202 .. cfunction:: int PyDateTime_TIME_GET_MINUTE(PyDateTime_Time *o)
204 Return the minute, as an int from 0 through 59.
206 .. versionadded:: 2.4
209 .. cfunction:: int PyDateTime_TIME_GET_SECOND(PyDateTime_Time *o)
211 Return the second, as an int from 0 through 59.
213 .. versionadded:: 2.4
216 .. cfunction:: int PyDateTime_TIME_GET_MICROSECOND(PyDateTime_Time *o)
218 Return the microsecond, as an int from 0 through 999999.
220 .. versionadded:: 2.4
222 Macros for the convenience of modules implementing the DB API:
225 .. cfunction:: PyObject* PyDateTime_FromTimestamp(PyObject *args)
227 Create and return a new ``datetime.datetime`` object given an argument tuple
228 suitable for passing to ``datetime.datetime.fromtimestamp()``.
230 .. versionadded:: 2.4
233 .. cfunction:: PyObject* PyDate_FromTimestamp(PyObject *args)
235 Create and return a new ``datetime.date`` object given an argument tuple
236 suitable for passing to ``datetime.date.fromtimestamp()``.
238 .. versionadded:: 2.4