Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Converting a day number to a day name using calendar

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.

like image 447
Daniel Porteous Avatar asked Mar 05 '26 08:03

Daniel Porteous


1 Answers

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

>>> import calendar
>>> calendar.day_name[4]
'Friday'
like image 77
niemmi Avatar answered Mar 06 '26 22:03

niemmi