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

label based on time

Hello everyone,

 

How is it best to show a label based on time.

The label must be displayed every day from 11:00 am to 2:00 pm

 

Best regards, Raymond van der Horst

3 ACCEPTED SOLUTIONS

Accepted Solutions
BCLS776
Super User
Super User

In the Visible property of the label, paste this code:

If(
    DateDiff(Today(),Now(),Hours) >= 11 && DateDiff(Today(),Now(),Hours) < 14, 
    true, 
    false
)

This will use the user's local time zone to determine 11am and 2pm.

 

Hope that helps,

Bryan

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

View solution in original post

Many Thanx,

 

It works when I refresh the page. But if it has to start itself then it won't be visible. What could this be?

Do I have to place the video on another page and then navigate to another page at a time?

 

Thank you very much

 

Raymond

 

View solution in original post


@rho1967 wrote:

Many Thanx,

 

It works when I refresh the page. But if it has to start itself then it won't be visible. What could this be?

Do I have to place the video on another page and then navigate to another page at a time?

 

Thank you very much

 

Raymond

 


The behavior you're seeing is because Today() and Now() do not continuously re-evaluate on their own - they need deliberate action through a behavior formula (one that starts with "On") to return a new value.

 

One way to deal with this is to create and set a variable using a timer:

  1. Put varVisible in the Visible property you want to control
  2. Insert a timer on the screen, set it to auto-start, repeat, and make it non-visible
  3. Set the timer's duration to 60000 (one minute) and set its OnTimerEnd code to:
Set(varVisible,
    If(
        DateDiff(Today(),Now(),Hours) >= 11 && DateDiff(Today(),Now(),Hours) < 14, 
        true, 
        false
    )
)

Once per minute the app will re-evaluate the expression and toggle the variable & visibility of your control.

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

View solution in original post

6 REPLIES 6
BCLS776
Super User
Super User

In the Visible property of the label, paste this code:

If(
    DateDiff(Today(),Now(),Hours) >= 11 && DateDiff(Today(),Now(),Hours) < 14, 
    true, 
    false
)

This will use the user's local time zone to determine 11am and 2pm.

 

Hope that helps,

Bryan

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

View solution in original post

Many Thanks BCLS776

 

 

Only one question Bryan,

 

Is this also possible with minutes. example 16:15 until 17:02?

 

Regards,

Raymond

 


@rho1967 wrote:

Only one question Bryan,

 

Is this also possible with minutes. example 16:15 until 17:02?

 

Regards,

Raymond

 


Yes, you can make this work for other times too. Keep in mind the DateDiff function returns only whole numbers, so it would make more sense to base a time such as 17:02 on Minutes instead of Hours in the calculation. 17:02 = 17x60+2 = 1022 minutes after midnight for the condition.

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

Many Thanx,

 

It works when I refresh the page. But if it has to start itself then it won't be visible. What could this be?

Do I have to place the video on another page and then navigate to another page at a time?

 

Thank you very much

 

Raymond

 

View solution in original post


@rho1967 wrote:

Many Thanx,

 

It works when I refresh the page. But if it has to start itself then it won't be visible. What could this be?

Do I have to place the video on another page and then navigate to another page at a time?

 

Thank you very much

 

Raymond

 


The behavior you're seeing is because Today() and Now() do not continuously re-evaluate on their own - they need deliberate action through a behavior formula (one that starts with "On") to return a new value.

 

One way to deal with this is to create and set a variable using a timer:

  1. Put varVisible in the Visible property you want to control
  2. Insert a timer on the screen, set it to auto-start, repeat, and make it non-visible
  3. Set the timer's duration to 60000 (one minute) and set its OnTimerEnd code to:
Set(varVisible,
    If(
        DateDiff(Today(),Now(),Hours) >= 11 && DateDiff(Today(),Now(),Hours) < 14, 
        true, 
        false
    )
)

Once per minute the app will re-evaluate the expression and toggle the variable & visibility of your control.

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,285)