cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
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
Super User
Super User

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

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

Helpful resources

Announcements
Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

Microsoft Ignite

Microsoft Power Platform: 2021 Release Wave 1 Plan

Power Platform release plan for the 2021 release wave 1 describes all new features releasing from April through September 2021.

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Users online (18,811)