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 Apps / Button visibility with...
Power Apps
Answered

Button visibility within a time range

(0) ShareShare
ReportReport
Posted on by 37

Hi, I am trying to make a button visible within a time range. Currently I am just testing around. I created two labels (Label6 and Label6_2) to store current time using Now(). I am suspecting that maybe the way I store the current time is wrong. Previously, I only use one label to check the current time. But somehow the condition check seems like doesn't work. It will return false. I've tried using 'And', '&&', and other logical operator, but to no avail. The condition will only work if I put only one condition. But that will not satisfy the requirement.

 

My requirement is, for example, I need to button appear within 6pm to 7pm daily.

 

Mind to share if you have any idea?

 

rocky_puff_0-1626338059016.png

 

 

If((TimeValue(Label6.Text) > TimeValue("1:47:00.000 PM")) && ((TimeValue(Label6_2.Text)) < TimeValue("2:42:00.000 PM")), true, false)

 

 

Categories:
  • RusselThomas Profile Picture
    4,014 on at

    Hi @rocky_puff ,

    The Now() function just gets the current time at the time the function is run.  It doesn't keep tracking the time, so you'd need to use it with a timer that continuously fetches the time.

    Try adding a timer and set it's OnTimerEnd: property to 

     

    Set(gvarCurrentTime, Now());
    If(gvarCurrentTime > TimeValue("1:47:00.000 PM")) && (gvarCurrentTime < TimeValue("2:42:00.000 PM")), Set(showTimeBasedControls, true), Set(showTimeBasedControls, false))

     

    Set it to start automatically and set it's duration to 1000 (1 second).

    You can then set your time based controls Visibility: property to showTimeBasedControls.

    I haven't tested your timevalue comparisons, but assuming they work then this should handle the visibility for you.

    Hope this helps,

    RT

  • rocky_puff Profile Picture
    37 on at

    Hi @RusselThomas ,

     

    So I have followed your instruction. Did I do it correctly? But somehow it didn't work. The button does not appear. 

     

    rocky_puff_0-1626416807680.png

    rocky_puff_1-1626416850347.png

     

  • RusselThomas Profile Picture
    4,014 on at

    Hi @rocky_puff ,

    Apologies, it must also be on repeat.  If you leave it visible, you should see the timer running.

    Also, the control formula should be on either TimerEnd, or TimerStart - but not both.  If you set ayo to true on TimerStart, and then also switch it off based on a condition on TimerEnd, then your button will flicker on and off when it's supposed to be off.

    Lastly, make sure your button Visible: property is set to ayo

    I'll build a test this morning quick to check everything.

    Kind regards,

    RT

  • rocky_puff Profile Picture
    37 on at

    Hi @RusselThomas ,

     

    So I also tried Update Context like my code below. Another thing is, I'm not sure where to set Ayo. Thus, I create another timer to set Ayo at OnTimerStart and that timer has nothing at OnTimerEnd. Does my way valid? It feels right, but the button is not appearing. 

     

    Timer1

    Set(ayo,Button2.Visible)

     

    Timer2

    Set(gvarCurrentTime, Now());
    If((gvarCurrentTime > TimeValue("1:47:00.000 PM")) && (gvarCurrentTime < TimeValue("4:30:00.000 PM")), UpdateContext({ ayo: true }), UpdateContext({ ayo: false }))

     

  • Verified answer
    RusselThomas Profile Picture
    4,014 on at

    Hi @rocky_puff ,

    I ran a test this morning and picked up a few issues, but first some rules to help clarify;

    A variable can be either global, or local - but not both, as this causes issues.

    You can use Set(), or UpdateContext() to define ayo as true or false, but you shouldn't use both.

    If you use Set(), ayo will be defined and accessible across the entire app - this is a global variable.

    If you use UpdateContext(), ayo will be defined for the screen/page that you used it on, and will be specific to that page - this is a local variable.

    In my example, we set gvarCurrentTime to global (so it can be accessed from anywhere in the app) and ayo to local, so it's specific to the screen in which the buttons appear.  

    In this scenario, we only need one timer, and we only need to use one event handler

    Either OnTimerStart: or OnTimerEnd: - if you use both you may be using conflicting logic.

     

    With the above in mind, the Timer2 logic has two issues.  The first is your TimeValue() expression.  To ensure this is right, add a text label to your screen and set it's Text: property to 

    TimeValue("1:47:00.000 PM")

    On my side, this comes up blank - it only works if I remove the trailing .000, although this may be somehow influenced by regional settings.  If it shows you the time then it's fine - if not, try remove the trailing .000

    Once you can confirm the correct expression that gives you a Time value in your text label, copy the expression and remove the text label.

    Then, it's important to realise that when we test conditions, the things we're testing must be of the same type - so when testing date/datetime/time functions, we need to ensure we're checking date vs date, datetime vs datetime or time vs time. 

    In my example above, I neglected to convert Now(), which is a datetime, to a time value - before comparing it to another time value.  The TimeValue() converts text to time, which requires a text value to do this - so we have to first convert Now() to text so it can work with TimeValue(), then convert it to time to compare it to another TimeValue().

    Try this on a single timer OnTimerEnd: instead (and remove all other logic or timers you may have);

    Set(gvarCurrentTime, Now());
    If((TimeValue(Text(gvarCurrentTime)) > TimeValue("01:47:00 AM")) && (TimeValue(Text(gvarCurrentTime)) < TimeValue("04:30:00 PM")), UpdateContext({ ayo: true }), UpdateContext({ ayo: false }))

    The only other thing that needs to be configured is the button Visible: property being set to

    ayo

    Hope this helps,

    RT 

  • rocky_puff Profile Picture
    37 on at

    Hi @RusselThomas ,

     

    Thank you very much for the explanation and sharing! I just realized it too that the comparison was not of the same type. It works like a charm!

     

    Hope you have a very nice day 😉

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 350 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 318

#3
Mohsin Ali Profile Picture

Mohsin Ali 220

Last 30 days Overall leaderboard