cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
roccolord
Helper II
Helper II

Week number, in pad

How do I get the current week number in PAD?

3 REPLIES 3
MichaelAnnis
Super User
Super User

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:

 

MichaelAnnis_0-1630089526141.png

 

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!

 

tkuehara
Super User
Super User

Hi @roccolord 

 

You can use Python in PAD:

tkuehara_0-1630417576754.png

tkuehara_1-1630417596058.png

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:

tkuehara_2-1630417775812.png

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)

tkuehara_4-1630418743244.png

 

tkuehara_3-1630418688744.png

Please also notice this week number system considers the starting on Monday and ending on Sunday.

roccolord
Helper II
Helper II

nice thanks!

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,183)