cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

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
Highlighted
Dual Super User II
Dual Super User II

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 II
Super User II

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!

Highlighted
Dual Super User II
Dual Super User II

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

Highlighted
Helper V
Helper V

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
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Upcoming Events

Experience what’s next for Power Automate

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Top Solution Authors
Top Kudoed Authors
Users online (7,530)