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 Staff CarlosFigueira
Power Apps Staff

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
Power Apps Staff CarlosFigueira
Power Apps Staff

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.

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 Staff CarlosFigueira
Power Apps Staff

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

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.

rgparisoto
Level: Powered On

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.

akmiecik
Level: Powered On

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

Power Apps Staff CarlosFigueira
Power Apps Staff

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.

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

Power Apps Staff CarlosFigueira
Power Apps Staff

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
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (8,898)