cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JoaoMS
Regular Visitor

Problem comparing dates

Dear all, I'm starting this adventure with Power Automate, and I'm having the following error when comparing two dates: Unable to process template language expressions for action 'Condition' at line '1' and column '15242': 'The template language function 'int' was invoked with a parameter that is not valid. The value cannot be converted to the target type.'. I'm comparing the following dates wiht the Conditional "is equal to" Date 1: formatDateTime(utcNow(),'yyyy-MM-dd') Date 2: formatDateTime(addDays('1900-01-01',add(int(item()?['Reminder']),-2)),'yyyy-MM-dd') Where 'Reminder' is the Field Name of a column with dates from an Excel File with many registers. The idea is that when one register has its "Reminder" date equals to Today Date, proceeds to send an e-mail. I think I'm missing something in the expression for Date 2. Thanks in advance. Joao
1 ACCEPTED SOLUTION

Accepted Solutions

Hello @JoaoMS 

You could use the ticks function, which converts a date to a 100-nanosecond intervals, since January 1, 0001 12:00:00 midnight, and its perfect for comparing dates.

Therefore, you could use the following flow:

 

date_excel.png

 

 

Just a couple of things to take into account:

1) The if comparison is inside an apply to each loop, since we have to do the comparison for every excel row.

2) The utcNow() function get the time too, so that's the reason we convert it to only get the date.

 

Hope it helps!

Ferran

Did I answer your question? Please consider to mark my post as a solution to help others.
Proud to be a Flownaut!

View solution in original post

4 REPLIES 4
Amanthaper
Responsive Resident
Responsive Resident

Hi @JoaoMS try this expression formatDateTime(addDays('1900-01-01',dayOfMonth(addDays(item()?['Reminder'],-2))),'yyyy-MM-dd')

Cheers,

Aman

------------------------------------------------------------------------------------------------------
If my post helps you with your problem or answers your question, please mark it Solved or Answered. This helps anyone with similar challenges. If you like my response, please give it a Thumbs Up.
------------------------------------------------------------------------------------------------------

Hi @Amanthaper , thank you for the quick response. I tried the recommended expression however I got now the following error:

 

Unable to process template language expressions for action 'Condition' at line '1' and column '15242': 'The template language function 'addDays' expects its first parameter to be a string that contains the time. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#adddays for usage details.'.

 

I'm attaching some pictures about it. The dates from the Excel file ('Reminder' column) are in Date format, and I want them to be in that format, so I need to figure out how to change them in String format in order to compare them with "Today format"

 

Screen.pngScreen2.png

 

Thanks again.

Hello @JoaoMS 

You could use the ticks function, which converts a date to a 100-nanosecond intervals, since January 1, 0001 12:00:00 midnight, and its perfect for comparing dates.

Therefore, you could use the following flow:

 

date_excel.png

 

 

Just a couple of things to take into account:

1) The if comparison is inside an apply to each loop, since we have to do the comparison for every excel row.

2) The utcNow() function get the time too, so that's the reason we convert it to only get the date.

 

Hope it helps!

Ferran

Did I answer your question? Please consider to mark my post as a solution to help others.
Proud to be a Flownaut!

View solution in original post

JoaoMS
Regular Visitor

Hi @fchopo , now it works! thank you. I just made a few change in the second expression replacing the suggested '1900-01-01' by '1899-12-30':

 

ticks(addDays('1899-12-30',int(items('Apply_to_each')?['Reminder']),'yyyy-MM-dd'))

 

Screen3.png

 

Regards

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (2,187)