Thursday, 5 July 2018

Get current hour expression in Flow

This wasn't obvious to me!  I wanted to get the current hour to use in a condition in my Microsoft Flow.  I was looking to only perform an action between certain hours.

int(formatDateTime(convertFromUtc(utcnow(),'GMT Standard Time'),'HH'))

The expression uses utcnow() to get the current utc datetime. It's passed into the convertFromUtc function as the first argument.  The second argument is the region.

Finally, I use formatDateTime to format it using 'HH' which is 24 hour format.  This outputs a string value.  The int function is used to parse the string value to an integer type.

My flow has a condition that would only perform a sequence of actions between the hours of 6pm and 7am.

@or(less(variables('CurrentHour'), 7),greater(variables('CurrentHour'), 18))