2

Using the following command I was able to get the numerical day of the week for a given date:

from calendar import weekday

print(weekday(2015, 5, 8))

This block then produces the number 4. How can I convert this into Friday, preferably just using the calendar library. I've looked through the documentation as best as I can but couldn't find anything that would print out the full day name.

Cheers.

Daniel Porteous
  • 5,536
  • 3
  • 25
  • 44

3 Answers3

6

You can use calendar.day_name which is a list of week days in current locale:

>>> import calendar
>>> calendar.day_name[4]
'Friday'
niemmi
  • 17,113
  • 7
  • 35
  • 42
3

Never mind, I've found an answer but I'll leave the question up if anyone else is curious. The calendar library has an array called day_name with the days of the week in it:

An array that represents the days of the week in the current locale.

I was able to get the day by using:

from calendar import weekday, day_name

dayNumber = weekday(2015, 5, 8)
dayName = day_name[dayNumber]
Daniel Porteous
  • 5,536
  • 3
  • 25
  • 44
0

I think this will be a good way to solve

import calendar
print((calendar.day_name[calendar.weekday(2019, 9, 12)]).upper())
sayalok
  • 882
  • 3
  • 15
  • 30