-2

I have imported the datetime

from pathlib import Path
from datetime import datetime

then here i am getting an error

current_year = datetime.datetime.now().year
current_month = datetime.datetime.now().month

current_day = datetime.datetime.now().day
current_week = datetime.date(current_year, current_month, current_day).isocalendar()[1]

min_creation_date_to_be_considered_internal = "2023-03-15"
min_creation_date_to_be_considered_external = "2023-03-28"

enter image description here

if i use

current_year = datetime.now().year
current_month = datetime.now().month

current_day = datetime.now().day
# current_week = datetime.date(current_year, current_month, current_day).isocalendar()[1]
current_week = datetime.date(current_year, current_month, current_day).isocalendar()[1]
min_creation_date_to_be_considered_internal = "2023-03-15"
min_creation_date_to_be_considered_external = "2023-03-28"

enter image description here

2 Answers2

0

Rather you change your import to be:

import datetime   
...  
current_year = datetime.datetime.now().year

Or you change the method calls:

from datetime import datetime  
current_year = datetime.now().year  

Edit: the second error is due to the incorrect import. To fix it:

import datetime
current_year = datetime.datetime.now().year
...
current_week = datetime.date(current_year, current_month, current_day).isocalendar()[1]
jlgarcia
  • 333
  • 6
-1

The reason for the issue is that you are using datetime.datetime, instead you should use datetime only. This is because you have already imported datetime from the datetime module so use it directly. Try this code:

from pathlib import Path
from datetime import datetime

current_year = datetime.now().year
current_month = datetime.now().month
current_day = datetime.now().day
current_week = datetime.date(current_year, current_month, current_day).isocalendar()[1]

min_creation_date_to_be_considered_internal = "2023-03-15"
min_creation_date_to_be_considered_external = "2023-03-28"