cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Need help on the flow expression for due date

Hi, I have a simple flow setup for a SharePoint Task list which triggers when a task is marked as complete and creates a recurring task with due date of next year, I am using following formula for the due date: 

addDays(startOfMonth(addToTime(triggerBody()['DueDate'],12,'Month')),sub(dayOfMonth(triggerBody()['DueDate']),1),'yyyy-MM-dd')  
 
(The triggered flow takes due date of the completed task and creates a new task with same metadata but due date is handled through above expression)
 
It basically adds 12 months to the date value and keeps the day value as is (using the dayofmonth function). It works great. However in one off case where I had due date set to 5/1/2019, a user marked task as complete, so flow created another task with the due date of next year but the date I see is 4/1/2020, it should be 5/1/2020. Can someone help me modify the formula for expression so that the month number does not change in addition to the day number, only year value should be changing. 
 
See below screenshots for the flow,
First.JPGsecond.JPG
P.s: this is the only off case i came across, otherwise it was working great.
Thanks in advance. 
1 ACCEPTED SOLUTION

Accepted Solutions

@Anonymous 

 

Below I am using a compose to capture only the year and then advancing that value by 1, i also then grab the date and month in another compose and ultimately concatnate them to form the final date. This may work as a workaround until Microsoft fixes the issue with the formula above.

 

I have tested the following and it seems to work well.

Date_1.png

 

Expressions for the steps above.

 

Compose: Get Year

formatDateTime(body('Get_item')?['Date'],'yyyy')

Compose: Convert Year to Integer

int(outputs('Compose:_Get_Year'))

Compose: Advance Year

add(outputs('Compose:_Convert_Year_to_Integer'),1)

Compose: Get MM-dd

formatDateTime(body('Get_item')?['Date'],'MM-dd')

Compose: Concat Date

concat(outputs('Compose:_Get_MM-dd'),'-',outputs('Compose:_Advance_Year'))

That will advance the year and will keep the corret day/month.

 

Also to remove time from dates you can use the formatDateTime expression like below

formatDateTime(body('Get_item')?['Date'],'MM-dd-yyyy')

 

Hope this helps!

 

Thanks,

Zach

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

View solution in original post

9 REPLIES 9
v-yamao-msft
Community Support
Community Support

Hi @Anonymous ,

 

Thanks for feedback.

 

I have made some tests on my side and I found that when the due date is the first day of the month, the one off case you’ve mentioned will occur. And it works well on any other date.

 

I will help report this issue and back to you once I got any updates.

 

In addition, I have figured out a solution for this issue by using if function to check if it is the first day of a month:

 

if(equals(dayOfMonth(triggerBody()?['DueDate']),1),
addToTime(addDays(startOfMonth(addToTime(triggerBody()['DueDate'],12,'Month')),sub(dayOfMonth(triggerBody()['DueDate']),1),'yyyy-MM-dd'),1,'month'),
addDays(startOfMonth(addToTime(triggerBody()['DueDate'],12,'Month')),sub(dayOfMonth(triggerBody()['DueDate']),1),'yyyy-MM-dd'))

 

Please take a try with it on your side.

 

Best regards,

Mabel

 

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thanks @v-yamao-msft for the solution.

Unfortunately when input date is 5/1/2019, it does not work, see screenshot below. Looks like its still an issue with the first of the month, March 1st, 2019 returns march 3, 2020, also the timezone, hh:mm:Ss gets addded, please help.

 

Capture.PNG

@Anonymous 

 

Below I am using a compose to capture only the year and then advancing that value by 1, i also then grab the date and month in another compose and ultimately concatnate them to form the final date. This may work as a workaround until Microsoft fixes the issue with the formula above.

 

I have tested the following and it seems to work well.

Date_1.png

 

Expressions for the steps above.

 

Compose: Get Year

formatDateTime(body('Get_item')?['Date'],'yyyy')

Compose: Convert Year to Integer

int(outputs('Compose:_Get_Year'))

Compose: Advance Year

add(outputs('Compose:_Convert_Year_to_Integer'),1)

Compose: Get MM-dd

formatDateTime(body('Get_item')?['Date'],'MM-dd')

Compose: Concat Date

concat(outputs('Compose:_Get_MM-dd'),'-',outputs('Compose:_Advance_Year'))

That will advance the year and will keep the corret day/month.

 

Also to remove time from dates you can use the formatDateTime expression like below

formatDateTime(body('Get_item')?['Date'],'MM-dd-yyyy')

 

Hope this helps!

 

Thanks,

Zach

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Anonymous
Not applicable

@ZachRoberts  you are an absolute genius my friend, this keeps the logic nice and simple. Thank you so much for this, you have no idea how much this has helped me.

Awesome! I am glad that worked for you! Happy to help! Smiley Happy

 

-Zach

JP21
New Member

Hello, can use something like this for my problem? I would like to build a flow, where reminder is send after the file in folder is older then one year, I use uctnow, but that doesn´t work, I don´t want it to be based on today, but on modified date. Can you please advice, how to set this up? Thank you

Hi @JP21 ,

 

Yes you can use this flow with some modifications to achieve that. Please see the test flow I created below, I am starting the flow with a recurrence so that the flow will run daily or weekly depending on your need.

 

1.png

 

I am initializing a variable to store the modified date, this is what we will use to check if the file has not changed in a year. 

 

After grabbing the files from your document library you will want to add an apply to each with the following steps

 

2.png

 

Expressions for compose steps:

 Get Year:

formatDateTime(utcNow(),'yyyy')

 Convert Year to Integer:

int(outputs('Get_Year'))

Subtract Year:

sub(outputs('Convert_Year_to_Integer'),1)

Get MM-dd:

formatDateTime(utcNow(),'MM-dd')

Concat Date:

concat(outputs('Get_MM-dd'),'-',outputs('Subtract_Year'))

Set Variable:

set the variable we created above to the expression below

formatDateTime(items('Apply_to_each')?['Modified'],'MM-dd-yyyy')

 

Use a condition step to compare the Modified date variable to the date string we created if the file is less than or equal to the date.

 

3.png

 

Then you can setup what to do if it is older or not older

 

Thanks,

Zach

Hello Zach,

 

thank you for the instructions, I followed them all, just one additional question, in the last step when I put modified is less or equal to outputs, there are options for all the outputs in the string, should I choose the last one outputs for concat?

 

Thank you a lot

 

Hello Zach,

 

 

The flow is not working corectly, I don´t know why, the Set variable returns the same date for input and output and the flow triggers the action for if modified date is not less or equal to output it send a reminder, if it is nothing shoul happend, but keep getting the reminders. Also second question I would like for the flow to only consider approved items in the library and ignore pending or rejected items, I try to add a condition, but it´s not working. Should I start with that condition?

 

Capture.JPG

 

Capture 1.JPG

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Users online (4,063)