cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
msflow
Level: Power Up

Comparing dates without year

Hello,

 

I have a problem with comparing dates without year. The flow is for a birthday list:

When a employee his birthday is within now and 28 days, i want to update the employees column 'JarigDatum' to the integer 1.

Otherwise the integer has to be 0. The flow works but it dont gives the right employees to 1.  

 

https://imgur.com/27O74uJ

 

The first condition is:
@lessOrEquals(formatDateTime(items('Op_elk(e)_toepassen_3')?['JarigDatum'], 'MM/dd'), formatDateTime(utcNow(), 'MM/dd'))

the second is:

@greaterOrEquals(formatDateTime(addDays(items('Op_elk(e)_toepassen_3')?['JarigDatum'], -28), 'MM/dd'), formatDateTime(utcNow(), 'MM/dd'))

 

Maybe someone have ideas what i'm doing wrong?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Comparing dates without year

Hi @msflow,

 

Could you please show a bit more about the 'JarigDatum' column that you mentioned?

Could you please show more details about your SharePoint list?

Further, do you want to update the employees whose birthday is between utcnow() and utcnow()+28 days?

 

I suppose that you want to update the employees whose birthday is between utcnow() and utcnow()+28 days, is it true? I think there is something wrong with the formula that you provided within Condition box.

 

I have created a SharePoint list on my side and the data structure of it as below:2.JPG

Note: The Birth Date column is a Date type column, the JarigDatum column is Number type column and the default value of it is empty.

 

If you want to update the employees whose birthday is between utcnow() and utcnow()+28 days, I afraid that there is something wrong with the formula that you provided within your Condition box. 

 

I have made a test on my side and please take a try with the following workaround:

  • Add a Recurrence trigger, Interval set to 1 and Frequency set to Day.
  • Add a "Get items" action, specify Site Address and List Name.
  • Add a "Apply to each", input parameter set to output of "Get items" action.
  • Within "Apply to each" action, add a Condition, click "Edit in advanced mode", type the following formula:

 

@and(greaterOrEquals(formatDateTime(items('Apply_to_each')?['Birth_x0020_Date'], 'MM/dd'), utcNow('MM/dd')),lessOrEquals(formatDateTime(items('Apply_to_each')?['Birth_x0020_Date'], 'MM/dd'), formatDateTime(addDays(utcNow(), 28), 'MM/dd')))

 

 

  • Within "If/yes" branch of Condition, add a "Update item" action, specify Site Address and List Name. Id field set to ID dynamic content of "Get items" action. The JarigDatum field set to 1.
  • Within "If/no" branch of Condition, add a "Update item 2" action, specify Site Address and List Name. Id field set to ID dynamic content of "Get items" action. The JarigDatum field set to 0.

Image reference:3.JPG

 

The flow works successfully as below:4.JPG

 

5.JPG

 

In addition, you could also consider take a try to add two Conditions within your flow as below:

 

6.JPG

 

Within Condition box, click "Edit in advanced mode", type the following formula:

@greaterOrEquals(formatDateTime(items('Apply_to_each')?['Birth_x0020_Date'], 'MM/dd'), utcNow('MM/dd'))

Within Condition 2 box, click "Edit in advanced mode", type the following formula:

@lessOrEquals(formatDateTime(items('Apply_to_each')?['Birth_x0020_Date'], 'MM/dd'), formatDateTime(addDays(utcNow(), 28), 'MM/dd'))

 

 

Best regards,

Kris 

 

 

Community Support Team _ Kris Dai
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

4 REPLIES 4
Super User
Super User

Re: Comparing dates without year

Hi @msflow,

 

When things become complicate with expressions and conditions I would use variables. That way you can use the run history to debug your flow.

 

Use the Initialize Varibale action to create variable and then store your birth date in there and the 28 days away date in a separate variable.

 

Then your condition becomes a simple comparison of dates.

msflow
Level: Power Up

Re: Comparing dates without year

Hi @Pieter_Veenstra

 

I can't do the action 'Initialize Variable' in a for each loop. I can intialize it before the For-Each loop but then i got 1 variable with all birh-dates of all employees. 

 

Super User
Super User

Re: Comparing dates without year

Iniitialize a varible at the top of your Flow of the type that you need inside  the For Each but leave the value empty.

 

Then inside your for each you can use the Set Variable actions to set the variable to the value

Community Support Team
Community Support Team

Re: Comparing dates without year

Hi @msflow,

 

Could you please show a bit more about the 'JarigDatum' column that you mentioned?

Could you please show more details about your SharePoint list?

Further, do you want to update the employees whose birthday is between utcnow() and utcnow()+28 days?

 

I suppose that you want to update the employees whose birthday is between utcnow() and utcnow()+28 days, is it true? I think there is something wrong with the formula that you provided within Condition box.

 

I have created a SharePoint list on my side and the data structure of it as below:2.JPG

Note: The Birth Date column is a Date type column, the JarigDatum column is Number type column and the default value of it is empty.

 

If you want to update the employees whose birthday is between utcnow() and utcnow()+28 days, I afraid that there is something wrong with the formula that you provided within your Condition box. 

 

I have made a test on my side and please take a try with the following workaround:

  • Add a Recurrence trigger, Interval set to 1 and Frequency set to Day.
  • Add a "Get items" action, specify Site Address and List Name.
  • Add a "Apply to each", input parameter set to output of "Get items" action.
  • Within "Apply to each" action, add a Condition, click "Edit in advanced mode", type the following formula:

 

@and(greaterOrEquals(formatDateTime(items('Apply_to_each')?['Birth_x0020_Date'], 'MM/dd'), utcNow('MM/dd')),lessOrEquals(formatDateTime(items('Apply_to_each')?['Birth_x0020_Date'], 'MM/dd'), formatDateTime(addDays(utcNow(), 28), 'MM/dd')))

 

 

  • Within "If/yes" branch of Condition, add a "Update item" action, specify Site Address and List Name. Id field set to ID dynamic content of "Get items" action. The JarigDatum field set to 1.
  • Within "If/no" branch of Condition, add a "Update item 2" action, specify Site Address and List Name. Id field set to ID dynamic content of "Get items" action. The JarigDatum field set to 0.

Image reference:3.JPG

 

The flow works successfully as below:4.JPG

 

5.JPG

 

In addition, you could also consider take a try to add two Conditions within your flow as below:

 

6.JPG

 

Within Condition box, click "Edit in advanced mode", type the following formula:

@greaterOrEquals(formatDateTime(items('Apply_to_each')?['Birth_x0020_Date'], 'MM/dd'), utcNow('MM/dd'))

Within Condition 2 box, click "Edit in advanced mode", type the following formula:

@lessOrEquals(formatDateTime(items('Apply_to_each')?['Birth_x0020_Date'], 'MM/dd'), formatDateTime(addDays(utcNow(), 28), 'MM/dd'))

 

 

Best regards,

Kris 

 

 

Community Support Team _ Kris Dai
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

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: 357 members 5,646 guests
Please welcome our newest community members: