cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ldurland
Level: Powered On

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
MK1
Level: Powered On

Re: Using a button to update Date Time

Resolved. sucessfully. After changing the scenario.

Thanks 

View solution in original post

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

ldurland
Level: Powered On

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

Super User
Super User

Re: Using a button to update Date Time

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

ldurland
Level: Powered On

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?

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?

ldurland
Level: Powered On

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.

ldurland
Level: Powered On

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.

LjGk
Level: Powered On

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?

LjGk
Level: Powered On

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
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 265 members 5,792 guests
Please welcome our newest community members: