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

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

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

akmiecik 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

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.

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
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
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

Attending MBAS? Claim your badge

Attending MBAS? Claim your badge

Whether you’re streaming the digital event live, or watching on-demand, claim your attendee badge to sport on your profile.

‘Better Together’ T-Shirt Contest – Winner Announced!

‘Better Together’ T-Shirt Contest – Winner Announced!

And the winner is...

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Apps Community!

Power Platform 2020 release wave 1 plan

Power Platform 2020 release wave 1 plan

Features releasing from April 2020 through September 2020

‘Better Together’ Integration Forum Launch

‘Better Together’ Integration Forum Launch

We're launching a how-to forum where you can learn about how Power BI integrates with other Power Platform products.

Emergency Response & Monitoring Solution

Emergency Response & Monitoring Solution

Microsoft has created a regional government emergency response and monitoring solution that is built on Power Apps and Power BI.

Top Solution Authors
Top Kudoed Authors
Users online (5,424)