Dynamics 365 CE Date Conversion in Power Automate

Problem
Recently while working on Power Automate to send notification if custom activity record is completed before 15 day but still invoicing is not done yet, I was facing time zone issue while comparing date. I will provide details how I sold this issue.

Solution
Initially I started creating my flow where I used Recurrence and fetched my entity records based on the condition. After that I started comparing date using expression like below:
FormatDate

1. Here I formatted date from CRM to match particular format

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

2. Here I formatted the date I want to compare in the same format (15 days before current date)

addDays(utcNow(),-15,'yyyy-MM-dd')

But result was not coming correctly, while troubleshooting I printed date on a temp variable but dates were not coming correctly. There was difference in the date. While doing troubleshooting further I found we can use Convert Time zone action to convert date time to specific time zone, so I changed my flow like below
FormatDate1

After that I got date formatted correctly.

Summary
While working on the date comparison CRM date and the other date can be on the different format, you can use variable to print them and see if they are coming different format. If yes, you can use Convert Time Zone action.

Hope it will help someone!
Keep learning, Keep sharing !!

Leave a Reply

Your email address will not be published. Required fields are marked *