cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BrianHarmon
Advocate II
Advocate II

Time Conversion to Text Morning, Afternoon, Evening and Afterhours.

I need help with a flow. I am getting the time stamp from an email and I want to have Flow determine if its morning, afternoon, evening, afterhours and put that text in a cell on spreadsheet with other data. Example 2:05 PM should = Afternoon.

 

Time frame and Text to Place in spreadsheet
12:00 AM to 7:59 AM = "Afterhours"
8:00 AM to 11:59 AM = "Morning"
12:00 PM to 4:59 PM = "Afternoon"
5:00 PM to 10:00 PM = "Evening"

10:01 PM to 11:59 PM = "Afterhours"

 

I think I can do this with a condition but am at a loss.

1 ACCEPTED SOLUTION

Accepted Solutions
BrianHarmon
Advocate II
Advocate II

I actually found my solution. @ScottShearer posted on another similar issue.  However I needed to make the variable an type "integer" then it started working. Thank You Scott Shearer.

 

FlowImageMorning.png

 

View solution in original post

2 REPLIES 2
JohnAageAnderse
Memorable Member
Memorable Member

Hello @BrianHarmon 

With 4 simple variable actions, you can get the needed period for your use.

Variable action 1: Name = Hour, Type = Integer, Value = expression sub(int(formatDateTime(utcNow(),'HH')),1)

This variable will hold a value from 0 to 23 from the datetime that you provide - I use utcNow() above - swap with your datetime field.

 

Variable action 2: Name = HourToPeriod, Type = Array, Value = [0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,2,3,3,3,3,3,0,0]

This variable holds an array of 24 numbers, where 0 represents Afterhours ... and so forth.

 

Variable action 3: Name = PeriodToText, Type = Array, Value = expression createArray('Afterhours','Morning','Afternoon','Evening')

This variable holds the names of the periods.

 

Variable action 4: Name = PeriodName, Type = String, Value = expression first(skip(variables('PeriodToText'),first(skip(variables('HourToPeriod'),variables('Hour')))))

This variable convert the Hours into a Period and then into the Name.

Kind regards, John

BrianHarmon
Advocate II
Advocate II

I actually found my solution. @ScottShearer posted on another similar issue.  However I needed to make the variable an type "integer" then it started working. Thank You Scott Shearer.

 

FlowImageMorning.png

 

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Users online (3,251)