Given a 4 digit year, return the number of the day on which January 1st falls. 0 is Sunday, …, 6 is Saturday
Asked
Active
Viewed 83 times
-1
-
1This is probably too broad for SO. I would start writing some code and come back if you have a specific issue. – user3483203 Apr 11 '18 at 18:41
-
2However, you probably want: `datetime.datetime(1967, 1, 1).weekday()` Although Sunday is 6 in that format, and Monday is 0. – user3483203 Apr 11 '18 at 18:44
-
https://stackoverflow.com/questions/9847213/how-do-i-get-the-day-of-week-given-a-date-in-python Might be a dupe. – user3483203 Apr 11 '18 at 18:47
-
@Tshilidzi what did you try? – Amitkumar Karnik Apr 12 '18 at 06:17
1 Answers
0
You can use the datetime
library
import datetime
d = datetime.date(year, 1, 1)
weekday = d.isoweekday() % 7
The datetime
library starts all weeks on Monday, so you need to do a bit of a conversion to get Sunday
to be 0

Brendan Abel
- 35,343
- 14
- 88
- 118
-
@chrisz Yes, for `weekday()`, it's Mon-Sun (0-6), `isoweekday()` is still Mon-Sun, but it runs `1-7`, I'm just converting `7` to `0` – Brendan Abel Apr 11 '18 at 18:48