cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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

Resolved. sucessfully. After changing the scenario.

Thanks 

View solution in original post

16 REPLIES 16
Super User III
Super User III

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.

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

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

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?

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?

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.

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.

Frequent Visitor

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?

Frequent Visitor

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
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

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