How to determine the start date of the day of the current and last week in python?

I need to find the start date of the current and last week.

Here the weekday starts on Sunday. Thus, today I want the format "07-16-2017" to be "mm-dd-yyyy". I can get the date today easily datetime.datetime.now().strftime ("%Y-%m-%d"), but from sysdate I have to get the start day of the week.

I need a starter day date last week.

There is no default method in datetime for week information. Is there any other method in any python package to determine the required information?

+4
source share
1 answer

calendar.firstweekday(), , (0 - , 6 - ).

1) , firstweekday 1 ().

date.today() - datetime.timedelta(days=date.today().isoweekday() % 7)

.

2) , firstweekday 0 ().

date.today() - datetime.timedelta(days=date.today().isoweekday() % 7 - 1)

.

, - .

+2

Source: https://habr.com/ru/post/1681670/


All Articles