nehem
nehem

Reputation: 13672

Python weekday() for getting Sunday as 1 & Saturday as 7

What is the equivalent of datetime.isoweekday() for keeping Sunday as 1 and Saturday as 7 ?

Python's weekday() didn't help either. Are there alternative ways except getting clumsy by subclassing or doing weird arithmetic (addition, mod 7)?

I find it strange for not having a builtin method for a popular representation. - end of rant -

Upvotes: 4

Views: 2531

Answers (1)

John La Rooy
John La Rooy

Reputation: 304473

You can use a lookup table like this

[1,2,3,4,5,6,7,1][datetime.isoweekday(dt)] 

or

[1,2,3,4,5,6,7,1][dt.isoweekday()]

The first value in the table is never used of course

Upvotes: 4

Related Questions