I see option converting date Jan 22 2016
to day Monday
as a integer 0
using weekday()
.
But can I convert day as input to integer.
e.g. Friday
to 4
.
Input is not a date, it's just a day e.g. Friday
Asked
Active
Viewed 408 times
0

chickity china chinese chicken
- 7,709
- 2
- 20
- 49

user2661518
- 2,677
- 9
- 42
- 79
-
Possible duplicate of [How to convert datetime to integer in python](https://stackoverflow.com/questions/28154066/how-to-convert-datetime-to-integer-in-python) – Nazim Kerimbekov Feb 11 '19 at 21:56
-
What have you tried? Look into the `datetime` module? – Keldorn Feb 11 '19 at 21:56
-
Possible duplicate of [Weekday as String to number](https://stackoverflow.com/questions/34216472/weekday-as-string-to-number) – chickity china chinese chicken Feb 11 '19 at 22:07
2 Answers
3
IIUC, you need
>>> import calendar
>>> list(calendar.day_name)
['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
Having this list you can easily find index or build dict from it

Slam
- 8,112
- 1
- 36
- 44
3
There is a friendly calendar
module
import calendar
dict(zip(calendar.day_name,range(7)))['Monday'] #0

mad_
- 8,121
- 2
- 25
- 40