-1

Not seen this answered elsewhere. I want to automate a file to put in three headers based on the current week. Firstly i cant figure out how to get the current week. A similar thing to the excel formula weeknum(today()). So this week is week 25 in the fiscal calender.

I need the programme to work out the current week but then also input the previous 2 weeks so to pull back week 25,24 and 23. I cant just get the week number 25 above and -1 as when we hit week 1 next year the number will go to 0

Hope that makes sense. I heard date is a bit of a pain so hopefully its not too complicated.

H Card
  • 31
  • 4

1 Answers1

0

I'm not sure what you are trying to accomplish but maybe this will help.

import datetime
datetime.date.today().isocalendar()

It returns (2021, 25, 1) So to get just week 25, simply do:

 datetime.date.today().isocalendar()[1]
samor
  • 46
  • 2
  • Thats great, and gives me the week. I want to also get the previous two weeks. So to get week 24 I out a -1 at the end. My question also is this works for now but when i hit week 1 and use -1 it will go to week 0. Is there are way to lookup on week 25 to antoher list to pull back week 24 for last week etc – H Card Jun 22 '21 at 05:45