cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper I
Helper I

Help writing an expression

I'm new to Power Automate, I have reviewed documentation and references but can't quite figure out how to compose this expression. 

 

I'm trying to write an expression that will return meeting time suggestions for the following day between 8am to 5pm for multiple attendees. (weekdays preferably) 

 

Here's what I got so far but Im receiving an error:

 

addDays(startOfDay('yyyy-mm-ddTHH:MM',8),1)
addDays(startOfDay('yyyy-mm-ddTHH:MM',17),1)

 

Expression_1.PNG

 

Error/Output: 

Expression_2.PNG

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

 

Hi @Asuncion ,

 

Following the method of @edgonzales , you can use the following expression, which outputs null if the current time is not on a weekday.

if(and(greaterOrEquals(dayOfWeek(utcNow()),1),lessOrEquals(dayOfWeek(utcNow()),5)),addhours(startofday(convertFromUtc(utcNow(),'Pacific Standard Time')),32),null)

Please take a try.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Highlighted
Super User II
Super User II

@Asuncion 

Hi there.  So, a bit going on in yours.  Try this one first and then we can chat about the differences:

 

addhours(startofday(convertFromUtc(utcNow(),'Pacific Standard Time')),32)
 
addhours(startofday(convertFromUtc(utcNow(),'Pacific Standard Time')),41)
 
-Ed-
 
 

If you liked this reply, please give it a thumbs up! If this reply has answered your question or resolved your challenge, please consider marking it as a Solution. This helps other users find it more easily via search.

Highlighted
Super User II
Super User II

While you're testing the other one...here are some things I noticed:

In your expression,   addDays(startOfDay('yyyy-mm-ddTHH:MM',8),1), working from the inside out:

 

startofDay() wants the first component to be the actual date that you want the start of, ya?  So a more correct syntax could be something like startofDay(UTCNow()) - You don't necessarily need to worry about formatting since we're only doing math with the date at this point.  On that, though, 'MM' would be a two-digit month where 'mm' would be minutes.  I also think a lowercase hh would be good.    Here's a link to Custom date and time format strings.

 

think the ',8' part was trying to start the day at 8:00? Which I don't think is a valid structure or 'argument'.

 

The addDays() bit with the date and the ',1' was spot on.  I just think Power Automate didn't know how to process what you had as the date to add days to.

 

I went a little different direction, but still kept the 'start of day' since that seemed like a good reset point.

addhours(startofday(convertFromUtc(utcNow(),'Pacific Standard Time')),32)

With this one, we are converting the current UTC time to Pacific (I think I saw in another edit, that's where you were, but you can change it if you want), then looking at the start of that day (which essentially goes to midnight).

 

Then, since we're starting at midnight, I added 32 hours to get 08:00 the following day.  The second expression does the same exact thing, but adds 41 hours to get 17:00 the following day.

 

Hope that helps.

 

-Ed-

Highlighted

@edgonzales Thank you! The explanation truly helps give me a better understanding of how to write the expressions. This is all really new for me and trying to get more familiar with how it all works.

 

If I wanted to add something to control it only showing Mon-Fri between those hours. Is it possible to add a dayOfWeek function?

 

if(equals(dayOfWeek(utcNow(),1-6),addhours(startofday(convertFromUtc(utcNow(),'Pacific Standard Time')),32))

 

Highlighted

 

Hi @Asuncion ,

 

Following the method of @edgonzales , you can use the following expression, which outputs null if the current time is not on a weekday.

if(and(greaterOrEquals(dayOfWeek(utcNow()),1),lessOrEquals(dayOfWeek(utcNow()),5)),addhours(startofday(convertFromUtc(utcNow(),'Pacific Standard Time')),32),null)

Please take a try.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted

Thank @v-bacao-msft & @edgonzales !!

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Top Solution Authors
Top Kudoed Authors
Users online (8,131)