How to get weekday name in locale format from number in Python?
It it other method to get weekday name in Python that setting date to monday and using strftime('%a')
than adding timedelta(day=1)
.
How to get weekday name in locale format from number in Python?
It it other method to get weekday name in Python that setting date to monday and using strftime('%a')
than adding timedelta(day=1)
.
From this answer:
You can use
>>> import calendar
>>> dayoftheweek = 2
>>> calendar.day_name[dayoftheweek]
'Wednesday'
Where Monday = 0, Tuesday = 1
etc.
You can get the weekday names like this:
import locale
locale.nl_langinfo(locale.DAY_1)
locale.nl_langinfo(locale.DAY_2)
locale.nl_langinfo(locale.DAY_3)
locale.nl_langinfo(locale.DAY_4)
locale.nl_langinfo(locale.DAY_5)
locale.nl_langinfo(locale.DAY_6)
locale.nl_langinfo(locale.DAY_7)
Still a bit unsatisfactory that you cannot specify the weekday as an integer variable. In my environment you can do it like this, as it happens:
locale.nl_langinfo(locale.DAY_1 + x)
but the docs don't guarantee it.