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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Create Calendar event ...
Power Automate
Answered

Create Calendar event over multiple days between set times?

(0) ShareShare
ReportReport
Posted on by 45

Hello,
Any help with this issue would be greatly appreciated.
So essentially I have a Microsoft form that our project managers use to schedule events that can span over several days.
For examples in the photo i'd want the event to start 13/09/2022 at 23:00 and finish on 15/09/2022 at 06:00 but id want an event for each day so 13/09/2022 11pm - 14/09/2022 6am and 14/09/2022 11pm - 15/09/2022
However when I create the calendar events it will schedule the event for the whole day between them dates, is there anyway to get power automate to create an event for each day between the specific time period?

 

The dates and times are captured in an MS form as you can see on the last photo.

 

Any help greatly appreciated 🙂 

 

Screenshot 2022-09-06 at 12.03.55.pngScreenshot 2022-09-06 at 12.04.04.pngScreenshot 2022-09-06 at 12.25.21.pngScreenshot 2022-09-06 at 12.27.41.png

 
Categories:
I have the same question (0)
  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi @19Flash92 

     

    Using your example, I have placed the start and end dates into a compose.

     

    DamoBird365_0-1662465578615.png

    I have then calculated the number of days between both dates using the following:

    div(sub(ticks(formatDateTime(outputs('ComposeEnd'),'yyyy-MM-dd')),ticks(formatdatetime(outputs('ComposeStart'),'yyyy-MM-dd'))),864000000000)

     

    Note I have specified the datetime format because otherwise we will wrongly calculate the difference based on TIME also.

     

    Then I used the subtract from time action to remove the number of days calculated above from the end date (to get the start date with the end time, and then I add on 1 day.  I.e. the first day end date/time.

     

    DamoBird365_1-1662465693600.png

    Finally, use a select and range() as input, which starts at 0 and creates an array of days to add i.e. [0,1] we can add this number onto the start date and the firstenddate (as calculated).

    DamoBird365_2-1662465779610.png

    The end result is an array of start/end dates that you can use as input to an apply to each and insert item()?['start'] and item()?['end'] into your create event action.

    DamoBird365_3-1662465856650.png

    If you're new to arrays, try taking a look and playing along with the following video of challenges https://youtu.be/G3Q1WuZTWuY

     


    Cheers
    Damien

    Please take a look and subscribe to my YouTube Channel for more Power Platform ideas and concepts. Thanks

  • 19Flash92 Profile Picture
    45 on at

    Hello Damien,

     

    Really appreciate the detailed reply.

     

    I've tried to follow the steps and I'm now running into this error:

     

    Screenshot 2022-09-06 at 13.42.02.pngScreenshot 2022-09-06 at 13.42.17.png

  • 19Flash92 Profile Picture
    45 on at

    Most likely I have done something wrong on a previous step as here are the outputs:

     

    Screenshot 2022-09-06 at 14.02.30.pngScreenshot 2022-09-06 at 14.02.53.pngScreenshot 2022-09-06 at 14.02.57.png

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi @19Flash92 

     

    It's my bad, the expression for first end date should be adddays(body('Subtract_from_time'),1) - I don't know how I managed to copy that into the screenshot wrong.  Hopefully that sorts you.

     
    Damien
  • 19Flash92 Profile Picture
    45 on at

    Perfect working now, I've watched your array video and subscribed but I'm still lost on how I convert them Arrays into multiple calendar events. 

     

    If your able to help me with the last part I'll tip you with a coffee/beer 😄

  • 19Flash92 Profile Picture
    45 on at

    Also I tested this again but this time using 2 times over 5 days that don't go into separate days and it's basically created the out put below:

     

    Screenshot 2022-09-06 at 15.56.30.png

     

    Inputs I used were:

     

    Screenshot 2022-09-06 at 15.54.55.png

     

    Maybe I need to change something on my form to capture more data? 

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi @19Flash92 

     

    To create the events, you would add an apply to each, insert the select as input and the add expressions item()?['start'] and item()?['end'].

     

    DamoBird365_0-1662480195150.png

     

    Regarding your question about the 7th 12:00 to 10th 17:00, it's giving you

    7th - 8th

    8th - 9th

    9th - 10th

    What would you be expecting?

     

    Damien

  • 19Flash92 Profile Picture
    45 on at

    Hello Damien,

     

    Thanks for the reply.

     

    I'd expect:

    7th - 7th

    8th - 8th 

    9th - 9th

    10th - 10th 

     

    As the times don't overlap a day, so each event will take place on the same between 12:00 - 17:00. 

     

  • Verified answer
    DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi @19Flash92 

     

    I see what you mean.  So this will require some additional logic. 

     

    Based on 7th 12:00 to 10th 17:00

     

    if(less(body('Subtract_from_time'),parsedatetime(outputs('ComposeStart'))),1,0)

     

    If the subtract from time (7th 17:00) is less than the start time (7th 12:00), we add 1 day to the first end date, else 0.  Therefore the end date 7th 17:00 + 0 in this case.  I have added a compose to make this calculation and updated the composefirstenddate to adddays(body('Subtract_from_time'),outputs('ComposeTimeCheck')).

     

    if(less(body('Subtract_from_time'), parsedatetime(outputs('ComposeStart'))),0,1)

     

    If the subtract from time (7th 17:00) is less than the start time (7th 12:00), we add 0 days to the range or date difference, otherwise in this case, we add on 1.  I have added a compose for this calculation of logic too and I have updated the range to 

    range(0,add(outputs('ComposeDifferenceDays'),outputs('ComposeTimeCheckRange')))
     
    DamoBird365_0-1662494946284.png

    Based on testing....

    DamoBird365_1-1662494962037.png

     

    returns:

    DamoBird365_2-1662494987071.png

    and...

    DamoBird365_3-1662495022449.png

     

    returns:

    DamoBird365_4-1662495036993.png

    I tested on matching times too and you would get three events based on both times being the same.

     

    Please let me know if that works for you.  I was trying to think of more simple logic, but not sure how.

     

    Damien

  • 19Flash92 Profile Picture
    45 on at

    I’ll try this for sure, thanks for all the help so far.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 605

#2
Valantis Profile Picture

Valantis 340

#3
11manish Profile Picture

11manish 284

Last 30 days Overall leaderboard