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

Get the date of the last Thursday of the month

Hello,

 

May I know if it is possible to get the date of the last Thursday of the month? If yes, how can I do this?

 

Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User III
Super User III

Try this:

2021-04-19_06-47-28.png

Expressions are:

Select action...

From: range(0,31)
date: addDays(utcnow(), item())
day: dayOfWeek(addDays(utcNow(),item()))
month: formatDateTime(addDays(utcNow(),item()), 'MM')

Filter array...
@and
(
  equals(item()['day'], 4),
  equals(item()['month'], formatDateTime(utcNow(), 'MM'))
)

lastThursday...
last(body('Filter_array'))['date']

If you want to save yourself the bother of building this yourself, simply copy the code below and paste it as a new action into your flow, like this:

2021-04-19_06-56-02.gif

Here is the code:

{"id":"51185b0d-36b5-4ba1-9f6f-8c03-33049ab8","brandColor":"#8C3900","connectionReferences":{},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"last_Thursday_of_Current_Month","operationDefinition":{"type":"Scope","actions":{"Select":{"type":"Select","inputs":{"from":"@range(0,31)","select":{"date":"@addDays(utcnow(), item())","day":"@dayOfWeek(addDays(utcNow(),item()))","month":"@formatDateTime(addDays(utcNow(),item()), 'MM')"}},"runAfter":{}},"Filter_array":{"type":"Query","inputs":{"from":"@body('Select')","where":"@and\n(\n  equals(item()['day'], 4),\n  equals(item()['month'], formatDateTime(utcNow(), 'MM'))\n)"},"runAfter":{"Select":["Succeeded"]}},"lastThursday":{"type":"Compose","inputs":"@last(body('Filter_array'))['date']","runAfter":{"Filter_array":["Succeeded"]},"description":"last(body('Filter_array'))['date']"}},"runAfter":{}}}

Hope this helps.

Blog: tachytelic.net

YouTube: https://www.youtube.com/c/PaulieM/videos

If I answered your question, please accept it as a solution 😘

View solution in original post

5 REPLIES 5
v-duann-msft
Community Support
Community Support

Hi @annoying 

 

Thank you for posting.

 

According to your description, you would like to get the date of the last Thursday of the month. If any misunderstanding, please kindly let me know.

 

Here is the flow for your reference:

Expressions:

formatDateTime(addDays(outputs('Compose'),7),'MM')

formatDateTime(outputs('Compose'),'MM')

dayOfWeek(outputs('Compose'))

 

v-duann-msft_0-1618800752588.png

 

If you have any confusion, please let me know.

 

Hope the content above may help you.

 

Best regards,

Anna

Hello @v-duann-msft 

 

I have a schedule flow that happens on every Friday. Is it still possible for me to get the date of the last Thursday of the month with the solution you have given me?

Hi @annoying 

 

Thank you for reply.

 

Yes. That's possible. But we need to change expression accordingly.

 

Meanwhile, if you still keep running flow on Friday and want to operate any action on last Thursday, we need to change condition to check whether this is the last second Friday. Otherwise, the action on last Thursday will be ignored.

 

Thanks

Anna

@v-duann-msft May I know how can I do this? 

My flow is to send an email on the 2nd last Friday of the month. This email is to include the due date which is the last Thursday of the month.

 

This is how my flow works right now:

annoying_0-1618807051083.png

 

so I wanna get the date of the last Thursday that will be send out in the email. What do I have to change/add?

 

Paulie78
Super User III
Super User III

Try this:

2021-04-19_06-47-28.png

Expressions are:

Select action...

From: range(0,31)
date: addDays(utcnow(), item())
day: dayOfWeek(addDays(utcNow(),item()))
month: formatDateTime(addDays(utcNow(),item()), 'MM')

Filter array...
@and
(
  equals(item()['day'], 4),
  equals(item()['month'], formatDateTime(utcNow(), 'MM'))
)

lastThursday...
last(body('Filter_array'))['date']

If you want to save yourself the bother of building this yourself, simply copy the code below and paste it as a new action into your flow, like this:

2021-04-19_06-56-02.gif

Here is the code:

{"id":"51185b0d-36b5-4ba1-9f6f-8c03-33049ab8","brandColor":"#8C3900","connectionReferences":{},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"last_Thursday_of_Current_Month","operationDefinition":{"type":"Scope","actions":{"Select":{"type":"Select","inputs":{"from":"@range(0,31)","select":{"date":"@addDays(utcnow(), item())","day":"@dayOfWeek(addDays(utcNow(),item()))","month":"@formatDateTime(addDays(utcNow(),item()), 'MM')"}},"runAfter":{}},"Filter_array":{"type":"Query","inputs":{"from":"@body('Select')","where":"@and\n(\n  equals(item()['day'], 4),\n  equals(item()['month'], formatDateTime(utcNow(), 'MM'))\n)"},"runAfter":{"Select":["Succeeded"]}},"lastThursday":{"type":"Compose","inputs":"@last(body('Filter_array'))['date']","runAfter":{"Filter_array":["Succeeded"]},"description":"last(body('Filter_array'))['date']"}},"runAfter":{}}}

Hope this helps.

Blog: tachytelic.net

YouTube: https://www.youtube.com/c/PaulieM/videos

If I answered your question, please accept it as a solution 😘

View solution in original post

Helpful resources

Announcements
MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Users online (60,930)