cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TesDA
Level: Powered On

Create date in this month

In an expression I'd like to create a date dynamically based on that day during the month, either being the 15th or the last day of the month.

 

It should look something like:

 

if(dayOfMonth(utcNow())<15,
     date(current month, 15, currentyear), 
     date(currentmonth-1, lastday(currentmonth-1), currentyear))
 
I can figure everything out except how to construct the date, I dont see any function that would allow me to construct a day from a group of strings. In another system I have date(month, day, year), how do you do this here?
1 ACCEPTED SOLUTION

Accepted Solutions
Dual Super User
Dual Super User

Re: Create date in this month

Hi @TesDA 

 

Here is the mad max expression formula 🙂

 

if(less( int(dayofmonth(utcnow())),15),adddays(utcnow(),sub(15,int(utcnow('dd')))),adddays(startofmONTH(utcnow()),-1))

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

3 REPLIES 3
Highlighted
Super User
Super User

Re: Create date in this month

The Working with Dates and Times inside of your flows blog post outlines the basics for working with date/time, while this blog post breaks it down even further. Before working with date/time it is always recommended that you first format the date/time to a standard format, example: 

formatDateTime(utcNow(),'yyyy-MM-ddT00:00:00Z')

From there, instead of piping in actual date/times within your logic, start with creating variables for each date/time and pipe those variables into your date difference formula instead.  Flow Super User @vecerpa explains how to do just that in this accepted solution.

For figuring out the best logic for your date difference expression formula, the Workflow Definition Language schema reference is worth a look. It has date/time parameters like adddays(), addhours(), addminutes(), etc. 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Dual Super User
Dual Super User

Re: Create date in this month

Hi @TesDA 

 

Here is the mad max expression formula 🙂

 

if(less( int(dayofmonth(utcnow())),15),adddays(utcnow(),sub(15,int(utcnow('dd')))),adddays(startofmONTH(utcnow()),-1))

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

TesDA
Level: Powered On

Re: Create date in this month

This looks cool! Could you walk me through what its doing? There are some functions I dont understand.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 215 members 5,573 guests
Please welcome our newest community members: