cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pa111
Regular Visitor

Reset date picker to Today() after midnight

Hi all

I have a date picker called DatePickerTo in a Power App that is used to filter the items in a gallery. Users interact with this Power App 24/7.

The DefaultDate property for the date picker is set to Today().

I also have a Reset filters button with OnSelectReset(DatePickerTo).

After midnight (i.e. when the date increments by 1), if users click the Reset filters button, the date does not change to the correct value (i.e. the new current day). The only way to set it correctly is by manually changing it or refreshing the app.

Is there a way I can reset the value of Today() so that it updates to the correct date after midnight?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
BlessedCobba
Responsive Resident
Responsive Resident

@pa111 

From Docs 

For example, a label control with Label1.Text = Now() will not change while your app is active. Only closing and reopening the app will result in a new value.

The function will be reevaluated if it is part of a formula in which something else has changed. For example, if we change our example to involve a slider control with Label1.Text = DateAdd( Now(), Slider1.Value, Minutes ) then the current time is retrieved each time the Slider control's value changes and the label's text property is reevaluated.

What I suggest is just changing the way you give it the filter, maybe you could store it as a variable then when a user presses the reset button you could reset the variable? or just some other way that has it in a formula

View solution in original post

2 REPLIES 2
BlessedCobba
Responsive Resident
Responsive Resident

@pa111 

From Docs 

For example, a label control with Label1.Text = Now() will not change while your app is active. Only closing and reopening the app will result in a new value.

The function will be reevaluated if it is part of a formula in which something else has changed. For example, if we change our example to involve a slider control with Label1.Text = DateAdd( Now(), Slider1.Value, Minutes ) then the current time is retrieved each time the Slider control's value changes and the label's text property is reevaluated.

What I suggest is just changing the way you give it the filter, maybe you could store it as a variable then when a user presses the reset button you could reset the variable? or just some other way that has it in a formula

pa111
Regular Visitor

Thank you @BlessedCobba. I have implemented the fix as follows:

 

1. Add to the OnVisible property: Set(currentDate,Today())

2. Change the DefaultDate of the date picker to currentDate

3. Add to the OnSelect property of the reset button: Set(currentDate,Today())

 

I did some testing using the Second(Now()) command, set the default property for an input text control to a temporary variable, and verified that the number does change when you attempt to reset the input text control. It is difficult to verify that the date updates correctly without checking before and after midnight, but I think that this will work.

 

Thanks again!

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Ideas

Check out the New Ideas Site

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (3,630)