web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Comparing date & times...
Power Automate
Unanswered

Comparing date & times using greaterOrEquals()

(0) ShareShare
ReportReport
Posted on by 28

I have a scheduled flow where I want an action to take place if the following code in a filter array is true: 

 

@And(
lessOrEquals(formatDateTime(item()?['DateTimeInput'], 'MM/dd/yyyy h:mm tt'), formatDateTime(convertTimeZone(utcNow(), 'UTC', 'Pacific Standard Time'), 'MM/dd/yyyy h:mm tt')), 
greaterOrEquals(formatDateTime(addMinutes(item()?['DateTimeInput'], 30), 'MM/dd/yyyy h:mm tt'), formatDateTime(convertTimeZone(utcNow(), 'UTC', 'Pacific Standard Time'), 'MM/dd/yyyy h:mm tt'))
)

 

In other words, if the current time is past the time listed in variable "DateTimeInput", AND not yet more than 30 minutes past, trigger the action. 

 

Unfortunately, the function seems to be ignoring the AM/PM part? If "DateTimeInput" is set to '5/22/23 4:30 AM' and I run the flow on 5/22/23 at 4:45 PM, the function returns "true" and the flow proceeds, even though it should return "false" (the greaterOrEquals() statement should be false). The function also returns true in the reverse scenario...if "DateTimeInput" is set to '5/22/23 4:30 PM' and I run the flow on 5/22/23 at 4:45 AM. 

 

I thought maybe it was just comparing the hours/minutes, so I tried converting the time to 24-hour format using "H:mm", and I encountered the same problem.

 

Is there something I'm missing as to why this doesn't run properly? Is there a better way to write it? Thanks in advance!

 

Here's my flow setup:

JWallsKC_0-1684800146954.png

 

Categories:
I have the same question (0)
  • v-bofeng-msft Profile Picture
    on at

    Hi @JWallsKC ,

     

    Please try:

    @And(
    lessOrEquals(item()?['DateTimeInput'], convertTimeZone(utcNow(), 'UTC', 'Pacific Standard Time')), 
    greaterOrEquals(addMinutes(item()?['DateTimeInput'], 30), convertTimeZone(utcNow(), 'UTC', 'Pacific Standard Time'))
    )

     

    Best Regards,
    Bof

  • JWallsKC Profile Picture
    28 on at

    Thanks Bof, that seemed to do the trick. For the sake of learning, could you explain why your formula worked, and mine didn't? Does using the formatDateTime() function result in a string rather than a datetime format? I'm not sure why else my formula wouldn't work.

  • v-bofeng-msft Profile Picture
    on at

    Hi @JWallsKC ,

     

    If  you only compare with time , you could try:

    @And(
    lessOrEquals(int(formatDateTime(item()?['DateTimeInput'], 'HHmm')), int(formatDateTime(convertTimeZone(utcNow(), 'UTC', 'Pacific Standard Time'), 'HHmm'))), 
    greaterOrEquals(int(formatDateTime(addMinutes(item()?['DateTimeInput'], 30), 'HHmm')), int(formatDateTime(convertTimeZone(utcNow(), 'UTC', 'Pacific Standard Time'), 'HHmm')))
    )

     

    Best Regards,
    Bof

  • v-bofeng-msft Profile Picture
    on at

    Hi @JWallsKC ,

     

    Does using the formatDateTime() function result in a string rather than a datetime format? 

     

    Yes, that is the reason . What's more, if you want to get hours in 24 hour format , you should use HH instead of hh.

     

    Best Regards,

    Bof

  • JWallsKC Profile Picture
    28 on at

    Hi Bof,

     

    After initial tests yesterday looked good, I implemented the code and tried it today. The DateTimeInput was "5/23/2023 4:00 PM". Yet, the actions were triggered on every run between 12 pm and 3 pm, even though that timeframe shouldn't meet the criteria. I also tried to the formula you suggested to compare time only and that gave the same results. I'm totally confused as to how it's getting "true". 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard