How do I get the current week number in PAD?
I assume you mean the week of the year. Below says '(Today - 1/1/(of this year) in Days) / 7; rounded up = the week of the year we are in:
I tested this for "CurrentDateTime = 1/8/21" and it brought back week 2 and tested it for "CurrentDatetime = 1/7/21" and it brought back week 1. So, it should work. As a double check, I got Week 35 of the year.
Depending on how you want to deal with what classifies as a week, you may need to adjust the start date each year. So, how 1/1/21 was on a Friday, but you want all weeks to start on Monday, then you will need to delete the 1/1/%Today_yy% and just replace it with 12/28/20 so that week 1 starts on that Monday. If you do this, you will need to remember to replace it each year.
Best of luck!
Hi @roccolord
You can use Python in PAD:
import datetime
week = datetime.date(%CurrentDateTime.Year%, %CurrentDateTime.Month%, %CurrentDateTime.Day%).isocalendar()[1]
print(week)
Please notice it uses the ISO week date standard (ISO-8601), which means that if you try to run this script with 1/1/2021, it will return week 53:
If you want to consider 1/1/2021 the first week, then you need to adjust the code:
import datetime
week = datetime.date(%CurrentDateTime.Year%, %CurrentDateTime.Month%, %CurrentDateTime.Day%).isocalendar()[1]
first_week = datetime.date(%CurrentDateTime.Year%, 1, 1).isocalendar()[1]
if first_week == 52 or first_week == 53:
if %CurrentDateTime.Month% == 1 and week == 52 or week == 53:
print(1)
else:
print(week+1)
else:
print(week)
Please also notice this week number system considers the starting on Monday and ending on Sunday.
nice thanks!