[Tutor] Through a glass, darkly: the datetime module

Richard D. Moores rdmoores at gmail.com
Sun Oct 7 01:19:11 CEST 2012

On Fri, Oct 5, 2012 at 7:15 AM, Walter Prins <wprins at gmail.com> wrote:

> Does this hint help?
>>>> import datetime
>>>> mydate = datetime.date(2012,10,5)
>>>> mydate = mydate + datetime.timedelta(days=30)
>>>> print mydate
> 2012-11-04

Yes! Thanks to all for their rapid responses.

But now I'm thinking it would be handy to not only know that, say, 500
days from today is 2014-02-18, but to know what day if the week that
is. I suppose the calendar module is to be used for this, but I
haven't been able to get it to work for me. So what day of the week IS

The docs say
calendar.weekday(year, month, day)
Returns the day of the week (0 is Monday) for year (1970–...), month
(1–12), day (1–31).

>>> import calendar
>>> calendar.weekday(2014, 2, 18)

That "1" means Tuesday, right? But how can I use calendar to print out
that word, "TUESDAY"?



More information about the Tutor mailing list