cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jacoheymans
Frequent Visitor

show Button only after a certain date and time

Hi, I'm currently building a small app for a workshop and the people attending will have to do certain things at certain times.

I currenty have 3 buttons - one for the morning, lunch and when the day ends. 

 

I thought if I apply an if statement to the control (button) visibility it would work - but it does not look like the if runs in the app. i get it to change when I'm in the code but nowhere else? 

 

this is my sample 

If ( Now() >= DateTimeValue( "12/05/2019, 12:15:00 PM" ), true, false) 

the statement above will return true and false when the date is in future.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-yutliu-msft
Community Support
Community Support

Hi @jacoheymans

Do you want to use Now() function to represent the current time?

Now() function will only return a different value if the formula in which it appears is reevaluated. If nothing else changes in the formula then it will have the same value throughout the execution of your app.

This means that it will return time that the formula is reevaluated. It will not change with current time automatically. 

So to avoid the time was invalid, I suggest you add a button to set current time and then use this time to justify.

The time will be the time value that you click on the button. Or you could also set the screen's OnVisible.

For example:

Set a button's OnSelect/screen's OnVisible:

Set(currentime,Now())

Then use this variable to justify.

If ( currentime >= DateTimeValue( "12/05/2019, 12:15:00 PM" ), true, false) 

 

 

 

Best regards,

Community Support Team _ Phoebe Liu
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

9 REPLIES 9
mdevaney
Super User
Super User

@jacoheymans 

I do not detect anything wrong with this code.  Did you put this code in the VISIBLE property of the button? By the way, you can shorten the code by removing the IF statement. 

Now()>=DateTimeValue("12/05/2019, 12:15:00 PM")

 

You said "it changes when I am in the code but nowhere else."  What does that mean?  Please explain and send screenshots if possible.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

within this function bar- so once the app is published and runs, I wait until 12:15 - the button does not appear 

thanks for the tip of removing the if!

testing on my phone shows the button even if the date is in the future 

 

jacoheymans
Frequent Visitor

@mdevaney 

all of these screenshots were at the same time - on my pc as you can see the button hidden and my text field with the same statement has a value of false which is correct.

the same app on my phone is different and has a value of true.

but when the time comes the button does not "appear" by changing the value of its visibility 

@jacoheymans 

It appears there is some difference between viewing on the PC vs Phone.  My guess would be each devices has a different time on their internal clock.

 

My suggestion would be to put this code in a label, publish the app, and then compare the results from each device.

Now()

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

there is, look at the bottom of the screenshots. and that still isn't the issue

@jacoheymans 

Well, this is an interesting problem.  Lets try something slightly different here.  I want to be sure the DATE and TIME are what I expect so please input this code and test on both PC and Phone.  This is how I like to work with dates and times.  Please let me know the result.

Now()>=(Date(2019,12,5)+Time(12,15,0))

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up." 

v-yutliu-msft
Community Support
Community Support

Hi @jacoheymans

Do you want to use Now() function to represent the current time?

Now() function will only return a different value if the formula in which it appears is reevaluated. If nothing else changes in the formula then it will have the same value throughout the execution of your app.

This means that it will return time that the formula is reevaluated. It will not change with current time automatically. 

So to avoid the time was invalid, I suggest you add a button to set current time and then use this time to justify.

The time will be the time value that you click on the button. Or you could also set the screen's OnVisible.

For example:

Set a button's OnSelect/screen's OnVisible:

Set(currentime,Now())

Then use this variable to justify.

If ( currentime >= DateTimeValue( "12/05/2019, 12:15:00 PM" ), true, false) 

 

 

 

Best regards,

Community Support Team _ Phoebe Liu
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

@v-yutliu-msft 

 

this works great! but the next thign that happens is is the date time format that is not the same in powerapps it is mmddyyyy and on my device it is ddmmyy? how do you set the default in powerapps?

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 (1,195)