Skip to main content

Notifications

Community site session details

Community site session details

Session Id : lcfaICeLL2rNCfbFoHv+Pc
Power Automate - Building Flows
Answered

Take current time and round up to nearest quarter hour

Like (1) ShareShare
ReportReport
Posted on 3 Jul 2018 21:44:59 by

I need help with a flow app. I want to be able to take the current time, round that time up to the nearest quarter hour and then add 7 minutes to that time.  Then I want to delay the rest of my flow until that time comes. For example: Current time is 15:18, I want it to round up to 15:30 and then add 7 minutes to make it 15:37.  I then want to delay the rest of my flow until that time. 

 

 

  • WillPage Profile Picture
    1,907 on 02 Aug 2024 at 03:48:00
    Take current time and round up to nearest quarter hour
    Here is your formula to round a number between 0 and 59 to the next 15 minute interval:
    mul(add(int(first(split(string(div(float(outputs('Minutes')),15)),'.'))),1),15)
    Where outputs('Minutes') is the result of a formula like formatDateTime(utcNow(),'MM') or however you get your minutes.

    Here is proof it works:
     
     
    This is much cleaner than a bunch of if statements
  • ChrisSM Profile Picture
    46 on 01 Aug 2024 at 20:24:55
    Take current time and round up to nearest quarter hour
    @Chriddle It seems the formatDateTime solution breaks for times that start with 0, like 2024-07-08T17:02:00Z, because int() removes leading zeros. It's not elegant but I added an if statement to check for the length of the output. I changed from 15 to 30 for my own use case.
     
    addMinutes(
        formatDateTime(
            outputs('Compose_12'),
            concat(
                'yyyy-MM-ddTHH:',
                if(equals(length(string(mul(div(int(formatDateTime(outputs('Compose_12'), 'mm')),30),30))), 1), concat(0, mul(div(int(formatDateTime(outputs('Compose_12'), 'mm')),30),30)), mul(div(int(formatDateTime(outputs('Compose_12'), 'mm')),30),30))
            )
        ),
        30
    )
  • Chriddle Profile Picture
    7,689 Super User 2025 Season 1 on 04 Jul 2024 at 16:35:41
    Re: Take current time and round up to nearest quarter hour

    Same approach using formatDateTime

     

    addMinutes(
    	formatDateTime(
    		outputs('Compose'),
    		concat(
    			'yyyy-MM-ddTHH:',
    			mul(
    				div(
    					int(formatDateTime(outputs('Compose'), 'mm')),
    					15
    				),
    				15
    			)
    		)
    	),
    	15
    )

     

    As @ChrisSM correctly noted, the above expression fails with 1 digit as the minute.
    Therfore an update:

    addMinutes(
        formatDateTime(
            outputs('Compose'),
            concat(
                'yyyy-MM-ddTHH:',
                formatNumber(
                    mul(
                        div(
                            int(formatDateTime(outputs('Compose'), 'mm')),
                            15
                        ),
                        15
                    ),
                    '00',
                    'es-es'
                )
            )
        ),
        15
    )
  • Chriddle Profile Picture
    7,689 Super User 2025 Season 1 on 04 Jul 2024 at 16:17:20
    Re: Take current time and round up to nearest quarter hour

    My try:

    Cut off the seconds and reduce the minutes to the previous full quarter, then add 15 minutes (no issues with next hour/day/month etc).

    Chriddle_0-1720109474048.png

    Chriddle_1-1720109654846.png

     

     

     

     

    addMinutes(
    	concat(
    		slice(outputs('Compose'), 0, 14),
    		mul(
    			div(
    				int(slice(outputs('Compose'), 14, 16)),
    				15
    			),
    			15
    		)
    	),
    	15
    )

     

     

     

     

     

  • WilvertB Profile Picture
    4 on 04 Jul 2024 at 14:15:32
    Re: Take current time and round up to nearest quarter hour
    As I came across this post when searching for this issue, since there still seems to be no out-of-the-box solution, I will post my solution for other people who might need it.
     
    This works in separate compose actions or you can make a single long one, combining the formulas. Should also work with AM/PM times if in the last step the formatDateTime is changed accordingly.
     
    Probably someone else will have a more compact/optimised version but here you go.
     
    "TIMEINPUT": Time input
     
    The seconds:
    "OUTPUTSECONDS"div(add(int(formatDateTime(TIMEINPUT'ss')), 30), 60) = either 0 or 1
     
    The minutes:
    "OUTPUTMINUTES"mul(div(add(add(int(formatDateTime(TIMEINPUT'mm')), 7), OUTPUTSECONDS), 15), 15) = either 0, 15, 30, 45 or 60
     
    The hours:
    "OUTPUTHOURS"formatDateTime(addHours(TIMEINPUT, if(equals(OUTPUTMINUTES, 60), 1, 0)), 'HH')
     
    The full time:
    formatDateTime(concat(OUTPUTHOURS':', if(equals(OUTPUTMINUTES, 60), 0, OUTPUTMINUTES), ':00'), 'HH:mm:ss')
  • Verified answer
    Community Power Platform Member Profile Picture
    on 10 Jul 2018 at 18:34:20
    Re: Take current time and round up to nearest quarter hour

    Thank you! I ended using a combo of if statements to accomplish this.

     

    if(lessOrEquals(variables('Minutes'),15),add(sub(15,variables('Minutes')),7),if(and(greater(variables('Minutes'),15),lessOrEquals(variables('Minutes'),30)),add(sub(30,variables('Minutes')),7),if(and(greater(variables('Minutes'),30),lessOrEquals(variables('Minutes'),45)),add(sub(45,variables('Minutes')),7),if(greater(variables('Minutes'),45),add(sub(60,variables('Minutes')),7),0))))
  • GabrielStJohn Profile Picture
    on 10 Jul 2018 at 18:21:41
    Re: Take current time and round up to nearest quarter hour

    Hello, @Anonymous!

     

    If you have already posted your idea to the Flow Community Ideas Forum then you need to post the URL to your idea’s thread as a reply to this thread and then "Accept as Solution" on that reply so other users may vote for your Flow Idea and identify the information easily.

     

    Thank You!

     

    -Gabriel
    Flow Community Manager

  • Verified answer
    v-yamao-msft Profile Picture
    on 05 Jul 2018 at 06:49:26
    Re: Take current time and round up to nearest quarter hour

    Hi @Anonymous,

     

    I am afraid that there is no round function can be used in flow currently, you may consider submitting a request on Flow Ideas forum for this function:

    https://powerusers.microsoft.com/t5/Flow-Ideas/idb-p/FlowIdeas

     

    Besides, you may try to use the function if to return the value you want according to the existing time. Please take this doc for more details about the function:

    https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference

     

     

    Best regards,

    Mabel Mao

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Building Flows

#1
Churchy Profile Picture

Churchy 6

#2
Chriddle Profile Picture

Chriddle 4 Super User 2025 Season 1

#2
stampcoin Profile Picture

stampcoin 4

Overall leaderboard