cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper II
Helper II

Using a button to update Date Time

i have a datacard with the date picker and time controls. I can set the default of the datacard to Now() and it will populate the date and time with no issues. however i dont want the default to be now() as everytime i edit a record it will default to now() and not the date and time that was orignially selected in the record.

 

So how to i use a button to update the date and time datacard?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Helper IV
Helper IV

Re: Using a button to update Date Time

Resolved. sucessfully. After changing the scenario.

Thanks 

View solution in original post

16 REPLIES 16
Highlighted
Super User
Super User

Re: Using a button to update Date Time

Hi @ldurland

 

Here are the steps to do this.

 

Add a button and set the OnSelect property to this formula:

 

UpdateContext({DateNow: Now()})

Unlock your data card and change the default property of the text input control to the formula shown beneath. Modify the value of the second argument so that it refers to your data item.

 

If(IsBlank(DateNow), ThisItem.EndDate, DateNow)

DateTimeButton.JPG

 

Select your screen and set the OnHidden property to this:

 

UpdateContext({DateNow: Blank()})

You should now be able to use the button to set the date.

Highlighted
Helper II
Helper II

Re: Using a button to update Date Time

thanks a lot. thats what i was looking for. the transition from infopath to powerapps is a learning curve with a lot more to think about. 🙂

Highlighted
Super User
Super User

Re: Using a button to update Date Time

You're welcome @ldurland! Good luck with your transition from Infopath.

Highlighted
Helper II
Helper II

Re: Using a button to update Date Time

so the more i tested this i have come to the conclusion that its not working as intended. As i originally stated my datacard is made up of the date picker and a drop down for both hour and minute.

 

I can set the data card no problem to now() and it "updates" the datepicker and hour and minute dropdowns. However it seems that the actual date and time values do not get stored in the hourvalue, minute value, and datevalue fields. So when i save it doesnt actualy save the now() date and time.

 

any suggestions?

Highlighted
Super User
Super User

Re: Using a button to update Date Time

That sounds strange. If you were to update the hour and minute values manually (rather than using the now button), and to then save the record, does the form save the new value successfully to the data source?

Highlighted
Helper II
Helper II

Re: Using a button to update Date Time

yes it is strange. if using your scenario as soon as i navigate away from that screen and return it goes blank.

 

if i try and have a button on another screen to Set(vardate,now()) it also updates the card however it does not update the values as once i navigate away from that screen and return it is blank as well

 

Leaving the default to thisitem.date for the datacard and manually using the datepicker and dropdowns to time work as expected.

Highlighted
Helper II
Helper II

Re: Using a button to update Date Time

I am making a little progress but not using the button. I can set the default of the card to

If(varAppmode=FormMode.Edit,ThisItem.Date,Now())

and it retains the date values for the picker and dropdowns when changing screens.

 

 

Still unsure of what appears to be a simple task to update a date/time card with a now button. And further thought it should be able to update it if the card its populated or not.

 

One button click to set date time is much easier than 4 button clicks to set datepicker, time and minute.

Highlighted
Frequent Visitor

Re: Using a button to update Date Time

Hi,

Your solution works perfectly.

My problem is that I have 2 fields with a DateValue. I do not want both to be set to Now when a button is pressed. Do you have a solution?

Highlighted
Frequent Visitor

Re: Using a button to update Date Time

I've used your button to change date. When used the button also changes colour and text. How do you do to make the button keep this colour and text? Now the button changes back to original colour and text the next time you open the app.

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,961)