How to Determine Name of the Day in the Week
mensanator at aol.com
Thu Sep 18 05:34:02 CEST 2008
On Sep 17, 10:20 pm, Keo Sophon <keosop... at gmail.com> wrote:
> Fredrik Lundh wrote:
> > Henry Chang wrote:
> >> Instead of getting integers with weekday(), Monday == 0 ... Sunday ==
> >> 6; is there a way to get the actual names, such as "Monday ...
> >> Sunday"? I would like to do this without creating a data mapping. :)
> > if you have a datetime or date object, you can use strftime with the
> > appropriate formatting code. see the library reference for details.
> > if you have the weekday number, you can use the calender module:
> > >>> import calendar
> > >>> calendar.day_name
> > 'Monday'
> > (the latter also contains abbreviated day names, month names, and a
> > bunch of other potentially useful functions and mappings.)
> > </F>
> > --
> I've tried calendar.month_name, it displays empty string, while
> calendar.month_name is "January"? Why does calendar.month_name's
> index not start with index 0 as calendar.day_name?
Because there's no month 0?
And technically, weeks begin on Sunday, not Monday, but business
likes to think of Monday as day 0 of the week and it doesn't
conflict with any prior date format.
More information about the Python-list