Extracting days,months,years from datefield.

4,498 views
Skip to first unread message

Malte Beckmann

unread,
Dec 31, 2010, 6:53:02 AM12/31/10
to django...@googlegroups.com
I got a models.DateField and would like to extract months and years from that field so I can do calculations like a 'day in month' in a 'for month in months' loop in a 'for year in years' loop. How can I extract that info from a datefield? I have tried to read code written by others but their solutions are not very obvious to me.

James Bennett

unread,
Dec 31, 2010, 7:11:52 AM12/31/10
to django...@googlegroups.com

The value of a Datefield is a Python datetime.date object. To see the
attributes of datetime.date instances, which include what you want
here, see the Python datetime documentation:

http://docs.python.org/library/datetime.html#date-objects


--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

Reply all
Reply to author
Forward
0 new messages