cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
clem6329
Frequent Visitor

Date comparison through Flow power automated

Hi everyone, 

I have an issue with power automation through flow for my work Sharepoint document. 

 

I am trying to compare 2 dates (one being the due date for a project), and if this date is passed, I want to send an automated email to inform someone that the date is passed. 

I think that I have an issue with the format of my date in my column and the one that the power automation is using. Unfortunately, I could not find a solution that has already been shared in this forum.

Here is my column date used to reference the comparison:

clem6329_0-1666220297985.png

And here is my automated flow: 

clem6329_1-1666220398193.png

I would like to validate this flow and condition to be able to add second conditions in the future. 

Thanks a lot for your help.

Cheers,
Clem

1 ACCEPTED SOLUTION

Accepted Solutions

UTCNow() is already in the right format.  Adding 'u' in as a parameter either won't do anything or will return a completely wrong date/time.

 

The Left side should be just UTCNow() and the Right side should be

 

FormatDateTime(items('Apply_to_each_2')?['Date_x002b_48h'], 'u')

I would do some troubleshooting by adding a compose that contains both UTCNow() and the Date 48h value so you can see exactly what you are comparing.  But I've tested this using the formula I've provided and it should work.

 

 

One other question.  Why is there another loop in the Yes side of the Condition?  Could that be why you are getting 3 emails instead of one?



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

11 REPLIES 11
Sundeep_Malik
Super User
Super User

Hey @clem6329 

 

You will have to make both sides equal to make a comparison.

On left side the date is 10/04/2022 12AM

But with UtcNow() you are getting something like 10/20/2022 00:00:00Z

 

 

So do this:

 

 

On left side write:

 

formatDateTime(urdatedynamicexpression, 'MM/dd/yyyy')

 

And on right side write:

utcNow('MM/dd/yyyy')

 

Now the dates will be in same format.

Hi @Sundeep_Malik

Thank you for your answer. 

I imagine you were speaking about my condition expression (left and right side). 
So I have been able to add utcNow('MM/dd/yyyy') on the right side. But when I want to add formatDateTime(urdatedynamicexpression, 'MM/dd/yyyy') on the left side, I cannot select my dynamic expression (Date+48h). 

 

Here is a screenshot:

clem6329_0-1666306940271.png

I am probably missing something. Any idea of what it would be, please?

Thanks again,
Clem

Sundeep_Malik
Super User
Super User

Hey @clem6329 

Sometimes it happens.

 

Do this:

 

Add the dynamic expression without function. 

Double click on it. The expression would be highlighted. 

Copy it with ctrl+c shortcut.

Remove it.

 

After doing the above, write the formatDateTime action and paste the expression at the required position. 

There could be some @ {} symbols, remove them and save the expression.

 

Hope this will work.

Hi @Sundeep_Malik

Thanks for your reply. 

It did not work, as when I was double-cliquing, nothing happened. But I found a way to get the expression by copying the condition expression to the clipboard and selecting the needed part. 
So my expression is: 

formatDateTime(items('Apply_to_each_2')?['Date_x002b_48h'], 'MM/dd/yyyy'). 

I have pasted it on the left part, and on the right part, I have included the following: 
utcNow('MM/dd/yyyy'). 
 
On my SharePoint, I got 5 items with the dates being: 
clem6329_0-1666374851817.png

And when I execute my automated flow, I receive 5 emails (the result of my condition) for my 5 items, while I should receive 4 (for the red dates). 

Do you have any idea about this issue, please? I tried to change my condition from greater to lower, and I would receive 25 emails (multiples for the date/line), which makes me think that is not the proper condition. 

Thank you for your help,
Clem

 

clem6329
Frequent Visitor

Hi everybody, 

I still have some issues with my automated flow; I would like to do a quick recap: 

- I have a SharePoint document to keep track of my actions for different projects. Each action has a line.

- I would like to compare 2 dates: one is a due date for an action to be done, and one is the current day's date. 

- If the current date is past the due date, an automated email is sent to remind the person that the action needs to be done. 

 

He is my current condition: 

clem6329_0-1666644296153.png

The function is: 

formatDateTime(items('Apply_to_each_2')?['Date_x002b_48h'], 'MM/dd/yyyy')
 
clem6329_1-1666644357293.png

When I apply my condition, I receive an email for each line of my SharePoint (so for each action). And there is no distinction if the current date is past the due date or not. I have tried to change my condition from "is Greater than" to "is Less than" and the result is the same. 

I have followed @Sundeep_Malik remarks but unfortunately I still have some issues. 
Do anybody have an idea of my mistake(s)? 

Thank you so much for your help. 

Cheers,

Clem

Hi everyone, 

I still have the same issue that I described in my previous answer. I tried a few things today, but nothing changed. @Sundeep_Malik, do you have an idea, please? 

 

Also, I have added a second condition. I am using another column of my Sharepoint; if this column says "No" and the date is passed, than I want my flow to send an automatic email. But unfortunately nothing happen when both condition are applied (if I have only the date condition, an email is sent for each row of my Sharepoint document, wether the date is passed or not). 

Here is my condition:

clem6329_0-1666826659938.png

Any idea? 

Thank you for your help. 
Best regards,

Clem

Sundeep_Malik
Super User
Super User

@clem6329 

I would have definitely helped if I could.

 

Tagging others who might be able to help.

 

@Expiscornovus 

@Pstork1 

@v-liwei-msft 

@v-yujincui-msft 

@v-qiaqi-msft 

If you want to compare the output of a FormatDateTime() function with UTCNow() then you want both of them to be in ISO 8601 format.  The only time you want to use a static mask like "MM/dd/yyyy" is when you are trying to remove the time portion to see if two dates are equal to each other.  But to see if one is greater than the other you need to use a sortable version of ISO 8601.  The formatDateTime function you want will look like this. 'u' is the code for the standard ISO 8601 universal sortable DateTimeFormat. It should always be used when doing comparisons.

formatDateTime(items('Apply_to_each_2')?['Date_x002b_48h'], 'u')

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
clem6329
Frequent Visitor

Hi @Sundeep_Malik and @Pstork1

@Sundeep_Malik , thank you so much for your help; I really appreciate that you tagged more people. 

@Pstork1 , thank you for your answer. Unfortunately it did not work, I still received emails for dates that are greater than the current date. 
I have tried multiple things: 

- Only modify the right part of my condition, and replace the function with: formatDateTime(items('Apply_to_each_2')?['Date_x002b_48h'], 'u'). Result: No email received at all (I should have received 1 email). 

- Modify both side, with the left side being: utcNow('u'), and the rigt side being: formatDateTime(items('Apply_to_each_2')?['Date_x002b_48h'], 'u'). Result: 3 emails received for 3 lines (I should have received only 1). 
- Modify both side, with the left side being: utcNow(), and the rigt side being: formatDateTime(items('Apply_to_each_2')?['Date_x002b_48h'], 'u'). Result: 3 emails received for 3 lines (I should have received only 1). 
 
clem6329_0-1666908235804.png

And here are the dates that I compare with utcnow():

clem6329_1-1666908420814.png

Edit: I did a last test by removing the time in my column and I received 3 emails, when I should have received only 1.

 

Thanks again for your help,
Clem

UTCNow() is already in the right format.  Adding 'u' in as a parameter either won't do anything or will return a completely wrong date/time.

 

The Left side should be just UTCNow() and the Right side should be

 

FormatDateTime(items('Apply_to_each_2')?['Date_x002b_48h'], 'u')

I would do some troubleshooting by adding a compose that contains both UTCNow() and the Date 48h value so you can see exactly what you are comparing.  But I've tested this using the formula I've provided and it should work.

 

 

One other question.  Why is there another loop in the Yes side of the Condition?  Could that be why you are getting 3 emails instead of one?



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
clem6329
Frequent Visitor

Hi @Pstork1 , 

Thank you so much for your help. You were right; it works. My issue was that I did call out to send an email to each item if my condition was 'Yes'. I changed it to have 'send email' only, and it works. 

I have added as well my second condition, and everything works fine. 
Thank you so much for your precious help. 
Have a good weekend,
Clem

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (2,261)