cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DarrenM96
Frequent Visitor

Time Stamp Date Field with Current Date and Time Using Button - PowerApps

Hello PowerApps community,

 

I have a Canvas App connected to a SharePoint list. I want to add a button that will update the form with the current date and time.

 

DarrenM96_0-1607636439481.png

 

My current code for OnSelect button is:

UpdateContext({vInTime:true});
Reset(DateValue1);
Reset(HourValue1);
Reset(MinuteValue1);
UpdateContext({vInTime:false})

 

But I am not sure to set the fields to the current date and time.

 

On the default properties of date, hour, and minute, I have the following, respectively: 

If(
vInTime,
Today(),
Parent.Default
)

 

--

If(
vInTime,
Hour(Now()),
Text(
Hour(Parent.Default),
"[$-en-US]00"
)
)

--

If(
vInTime,
Minute(Now()),
Text(
Minute(Parent.Default),
"[$-en-US]00"
)
)

 

Any help here would be greatly appreciated.

 

-DMann96

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@DarrenM96 

Duh...sorry about that!  Typo on my part.

Should be UpdateContext({lclTime: Now()})

 

That should clear that up.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

6 REPLIES 6
RandyHayes
Super User III
Super User III

@DarrenM96 

Your variable you are setting before and after in your formula is going to put the results back to the Parent.Default.

Instead consider the following:

UpdateContext({lclTime, Now()})

For your DatePicker, set the Default to the following:

Coalesce(lclTime, Parent.Default)

 For your Hour dropdown:

Text(Hour(Coalesce(lclTime, Parent.Default)), "00")

And for the Minute Dropdown:

Text(Minute(Coalesce(lclTime, Parent.Default)), "00")

 

The Dropdowns will change automatically based on these formulas.

 

Also, either in your OnHidden or OnVisible (or some other action as needed), set the lclTime to Blank:

UpdateContext({lclTime, Blank()})

or else all of your entries will be based on that time at the press of the button.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Amazing response time, thank you!

 

So just to follow up because I do not quite understand yet. Do i put the following formula into the OnSelect function of the button?

UpdateContext({lclTime, Now()})

 Also, what is the lclTime? Power Apps does not seem to recognize it. Is this some kind of variable I need to set up or declare?

 

Thanks again,

-DM 

RandyHayes
Super User III
Super User III

@DarrenM96 

Yes, follow the steps I outlined.  You only need the UpdateContext on the OnSelect.  The rest will happen by itself.
Yes, lclTime is the name of the variable you are creating with the UpdateContext.

 

Also, I didn't mention it, but to be sure, your Items properties for the Hour dropdown should be : ForAll(Sequence(24,0), Text(Value, "00"))
And your Items properties for the Minute should be:  ForAll(Sequence(60, 0), Text(Value, "00"))

 

This will give you 24 hour time selection.  The formatting is important because Default properties on Dropdowns compare themselves to the type of the items.  The above will take care of all of that.

 

Let me know if you need 12 hour at some point too.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Hello @RandyHayes 

 

The current format is not accepted and is pulling up errors. Am I missing anything?

I have adjusted the item properties to what you have suggested and that works.

 

OnSelect: DarrenM96_4-1607705742552.png

 

 

DarrenM96_1-1607705648480.png

 

DarrenM96_2-1607705667706.png

 

DarrenM96_3-1607705679696.png

 

DarrenM96_5-1607705783756.png

 

Thanks again,

-DM

RandyHayes
Super User III
Super User III

@DarrenM96 

Duh...sorry about that!  Typo on my part.

Should be UpdateContext({lclTime: Now()})

 

That should clear that up.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

You rock! Thank you sir.

 

-DM

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

PA Community Call

Power Apps Community Call

Next call is happening on April 21st at 8a PST.

MBAS Carousel

Sign up for our May 4th event!

May the fourth be with you, join us online!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Top Solution Authors
Top Kudoed Authors
Users online (52,266)