Re: How to Determine Name of the Day in the Week

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keo Sophon

    Re: How to Determine Name of the Day in the Week

    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_n ame[0]
    'Monday'
    >
    (the latter also contains abbreviated day names, month names, and a
    bunch of other potentially useful functions and mappings.)
    >
    </F>
    >
    --

    >
    Hi,

    I've tried calendar.month_ name[0], it displays empty string, while
    calendar.month_ name[1] is "January"? Why does calendar.month_ name's
    index not start with index 0 as calendar.day_na me?

    Thanks,
    Sophon
  • Mensanator

    #2
    Re: How to Determine Name of the Day in the Week

    On Sep 17, 10:20 pm, Keo Sophon <keosop...@gmai l.comwrote:
    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[0]
    'Monday'
    >
    (the latter also contains abbreviated day names, month names, and a
    bunch of other potentially useful functions and mappings.)
    >
    </F>
    >>
    Hi,
    >
    I've tried calendar.month_ name[0], it displays empty string, while
    calendar.month_ name[1] is "January"? Why does calendar.month_ name's
    index not start with index 0 as calendar.day_na me?
    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.
    >
    Thanks,
    Sophon

    Comment

    • Steven D'Aprano

      #3
      Re: How to Determine Name of the Day in the Week

      On Wed, 17 Sep 2008 20:34:02 -0700, Mensanator wrote:
      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.
      There's no "technicall y" about it. It's an arbitrary starting point, and
      consequently there are different traditions to it, even in English.

      Besides, I don't think many businesses think of "day 0" at all. Most
      people outside of IT start counting from 1, not 0.

      In British Commonwealth countries, Sunday is the last day of the week,
      not the first, although under American influence that's changing in
      Australia at least.

      In Poland, the week begins with Monday ("poniedziałek "). Tuesday,
      "wtorek", means "second day". Other Slavic countries also start with
      Monday.

      Similarly, the Lithuanian calendar simple enumerates the days of the
      week, starting with Monday, "pirmadieni s" ("first day").

      In China, there are at least three different systems of naming the week
      days. In two of them, the week starts with Sunday, but in the third
      system, Sunday is "zhoumo" ("cycle's end") and Monday is zhouyi ("first
      of cycle").



      --
      Steven

      Comment

      • Mensanator

        #4
        Re: How to Determine Name of the Day in the Week

        On Sep 18, 12:01 am, Steven D'Aprano
        <ste...@REMOVE. THIS.cybersourc e.com.auwrote:
        On Wed, 17 Sep 2008 20:34:02 -0700, Mensanator wrote:
        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.
        >
        There's no "technicall y" about it.
        Sure there is, within the tradition I was refering to.
        Within that tradition, the start of the week isn't arbitray.

        Besides, the documentation specifically says it's using
        the European system

        <quote>
        By default, these calendars have Monday as the first day
        of the week, and Sunday as the last (the European convention).
        Use setfirstweekday () to set the first day of the week to
        Sunday (6) or to any other weekday.
        </quote>

        So, by default, Python doesn't use the American convention
        of weeks starting on Sunday (an American technicality).
        This does not contradict what I said.
        It's an arbitrary starting point,
        Amongst different systems, it's never arbitrary within a system.
        and
        consequently there are different traditions to it, even in English.
        I know, that's why I added the caveat.
        >
        Besides, I don't think many businesses think of "day 0" at all. Most
        people outside of IT start counting from 1, not 0.
        The accounting software I use to fill out my timesheet
        electronically was obviously created by IT people and
        the week begins on Monday. Their will is, of course,
        forced on all employees whether they are IT or not.
        >
        In British Commonwealth countries, Sunday is the last day of the week,
        not the first, although under American influence that's changing in
        Australia at least.
        >
        In Poland, the week begins with Monday ("poniedzia³ek" ). Tuesday,
        "wtorek", means "second day". Other Slavic countries also start with
        Monday.
        >
        Similarly, the Lithuanian calendar simple enumerates the days of the
        week, starting with Monday, "pirmadieni s" ("first day").
        >
        In China, there are at least three different systems of naming the week
        days. In two of them, the week starts with Sunday, but in the third
        system, Sunday is "zhoumo" ("cycle's end") and Monday is zhouyi ("first
        of cycle").
        Last time I was in Borders, I don't recall seeing any
        Polish, Lithuanian or Chinese calendars for sale.
        >
        --
        Steven

        Comment

        Working...