cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
RezaDorrani
Level 10

Re: Create date in this month

Hi @TesDA 

 

Here is the mad max expression formula Smiley Happy

 

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

3 REPLIES 3
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!

RezaDorrani
Level 10

Re: Create date in this month

Hi @TesDA 

 

Here is the mad max expression formula Smiley Happy

 

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

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
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020

thirdimage

Flow Community User Group Member Badge

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

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 Flow Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 246 members 2,516 guests
Please welcome our newest community members: