M
M
McVoVaN2020-09-01 10:58:19
Python
McVoVaN, 2020-09-01 10:58:19

How to get the week number of the year?

How to get current week number?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sswwssww, 2020-09-01
@McVoVaN

import datetime

week_number = datetime.datetime.today().isocalendar()[1]
print(week_number)

S
SKEPTIC, 2020-09-01
@pro100chel

1. Take the date datetime then translate it into days, days and months,
2. then divide by 7, if the number was divisible by 7, do nothing, if it was not divided by 7, then add 1
3. remove the fractional part - here you have the week number

M
milssky, 2020-09-01
@milssky

For example, you can yank this
Week number -- the second element of the count tuple. See the documentation for more details.

import datetime

print(datetime.date(2020,9,1).isocalendar())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question