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

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 I
Helper I

nice thanks!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Top Kudoed Authors
Users online (1,960)