cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

How to set current date as default date in date picker everytime page loads

How to set current date as default date in date picker everytime page loads?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Power Apps
Power Apps

Re: How to set current date as default date in date picker everytime page loads

Got it. In order for controls in PowerApps to understand changes in properties (such as the DefaultDate property in the date picker), then the value needs to change. One way to do that is to make two UpdateContext calls in the OnVisible property of that screen, something along the lines of

UpdateContext({currentDate: Today() - 1}); UpdateContext({currentDate, Today()})

That will ensure that the value is changed, and the date picker will be notified of it, updating the selected date to the current day.

 

Another alternative, which is probably preferred, is to "Reset" the date picker control - which causes its selected date to go back to the default value. In this case, you can set the OnVisible property to

UpdateContext({currentDate: Today()}); Reset(DatePicker1)

Where 'DatePicker1' is the name of your date picker control.

View solution in original post

14 REPLIES 14
Highlighted
Power Apps
Power Apps

Re: How to set current date as default date in date picker everytime page loads

If you want to update a value on the page load, you can create a context variable with the current date on the OnVisible property of the page (screen), and then use that variable as the DefaultDate property of the date picker control:

Screen1.OnVisible: UpdateContext({currentDate: Today()})
DatePicker1.DefaultDate: currentDate

Where DatePicker1 is the name of the date picker control, and Screen1 is the name of the screen which contains the picker.

Highlighted
Anonymous
Not applicable

Re: How to set current date as default date in date picker everytime page loads

The problem is when I select a different date on my DateField and click on other screen, everytime I go back on the screen that contains my DateField, the DateField defaulted on the date which I set previously.

Highlighted
Power Apps
Power Apps

Re: How to set current date as default date in date picker everytime page loads

Got it. In order for controls in PowerApps to understand changes in properties (such as the DefaultDate property in the date picker), then the value needs to change. One way to do that is to make two UpdateContext calls in the OnVisible property of that screen, something along the lines of

UpdateContext({currentDate: Today() - 1}); UpdateContext({currentDate, Today()})

That will ensure that the value is changed, and the date picker will be notified of it, updating the selected date to the current day.

 

Another alternative, which is probably preferred, is to "Reset" the date picker control - which causes its selected date to go back to the default value. In this case, you can set the OnVisible property to

UpdateContext({currentDate: Today()}); Reset(DatePicker1)

Where 'DatePicker1' is the name of your date picker control.

View solution in original post

Highlighted
Anonymous
Not applicable

Re: How to set current date as default date in date picker everytime page loads

It works. One thing I noticed is that when I go back to the page that contains my DatePicker, PowerApps initially loads the previously selected date and subsequently changes the date to default date. Maybe it was a delay since I also refresh the database. What I did is to put the reset function on OnHidden property. Now when the page load, DatePicker is defaulted to current date.

Highlighted
Helper V
Helper V

Re: How to set current date as default date in date picker everytime page loads

Hi guys!

 

Anyone nows how can I get the complete date? Like these:

2018-05-17 06:06:00.000

 

Thank you.

 

Regards,

Robson.

Highlighted
Advocate I
Advocate I

Re: How to set current date as default date in date picker everytime page loads

Can you just put

Today()

in the DefaultDate value of the DataCard Value field?

i.e

DataCard tmp.jpg

Highlighted
Power Apps
Power Apps

Re: How to set current date as default date in date picker everytime page loads

That should work as well, as long as the app calls one of the form functions (NewForm, EditForm, ResetForm) prior to showing the form to the user, as it will cause the default value to be re-evaluated.

Highlighted
Anonymous
Not applicable

Re: How to set current date as default date in date picker everytime page loads

Hi All,

 

I have built a Customised PowerApp Using the Sharepoint List.

On customised form there is a date picker on which the date is set to Today().

When we click on add new item to the list then the date is appearing as today's date, but when i try to view the items that are created few days ago then the date is changing to today. HOW CAN I SET THE DATE PICKER PROPERTY TO WHEN NEW ITEM CREATED DATE AS TODAY AND WHEN VIEWING PERVIOUS ITEMS DATE SHOULD NOT CHNAGE TO TODAY.

Thanks,

MK

Highlighted
Power Apps
Power Apps

Re: How to set current date as default date in date picker everytime page loads

If the card is in a form, you can use an If expression based on the mode of the form; if it's New, use Today() as the default, otherwise use the existing value, something along the lines of the expression below:

If(
    EditForm1.Mode = FormMode.New,
    Today(),
    Parent.Default)

The blog post at https://powerapps.microsoft.com/en-us/blog/default-values-for-complex-sharepoint-types/ talks about setting default values for new items in forms; it's emphasis is for SharePoint lists, but the concepts apply to other data sources as well.

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 (6,060)