cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Community Support
Community Support

Re: show Button only after a certain date and time

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
Highlighted
Super User
Super User

Re: show Button only after a certain date and time

@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."

Highlighted
Frequent Visitor

Re: show Button only after a certain date and time

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!

Highlighted
Frequent Visitor

Re: show Button only after a certain date and time

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

 

Highlighted
Frequent Visitor

Re: show Button only after a certain date and time

@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 

Highlighted
Super User
Super User

Re: show Button only after a certain date and time

@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."

Highlighted
Frequent Visitor

Re: show Button only after a certain date and time

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

Highlighted
Super User
Super User

Re: show Button only after a certain date and time

@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." 

Highlighted
Community Support
Community Support

Re: show Button only after a certain date and time

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

Highlighted
Frequent Visitor

Re: show Button only after a certain date and time

@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
Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,675)