cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SandraAkujobi
Post Partisan
Post Partisan

DateTime Button

How do you create a date and time button on Power Apps, basically what I'm trying to do is create a clock in button that when an employee clicks it, it displays the date and time that the button was pressed and also a another button for clock out that will also display the date and time that person clocked out.

30 REPLIES 30

@WarrenBelzthanks so much for your help, I really appreciate it.

Thanks @SandraAkujobi ,

It is not as late tonight (9pm here) so brain is a bit better.  @PowerAddict is still welcome to come in. I also now have screen shots which I probably should have asked for earlier.

The errors you are getting is because your control names do not match the example code I gave you so you either need to:

  • Rename your controls to match this code or
  • Change the code to match your current control names.

So the Clock In control names I gave you are

  • ClockInTimeDay
  • ClockInTimeHour
  • ClockInTimeMinute

and the equivalent for Clock Out.

In the Reset, you need to refer to all six controls (three at a time)  by these names or the ones you give them

Defaults as follows

  • Date fields  - Today()
  • Hour fields -  Hour(Now())
  • Minute fields -  Minute(Now())

When you reset them, they should change to the current date and time and they will take care of writing the data to SharePoint.

Remember the Defaults also need to refer to the variable, so for example the default of the CheckInTimeHour would be

If(
   vInTime,
   Hour(Now()),
   Parent.Default
)

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

As you can see in the images the name of the Date fields on the left are called (ClockInTime/ClockOutTime), I don't have a field called CheckinTimeHour on my apps so that's where my confusion lies in. Its only the datetime field and buttons I'm trying to configure.

 

Screenshot (39)_LI.jpg

 

This is how the default property formula looks like for the ClockInTime field (date/time field), It doesn't recognise the name.

Screenshot (39).png

If I removed i.e Day, Hour and Minute, the ClockInTime is highlighted. Another thing is the Parent.default doesn't seem to fit into the formula, it's always seen as an error, why is that?

 

Screenshot (40).png

 

Also on the buttons the is also showing up as an error, I've tried removing the reset formula but it's still showing up as an error. The whole thing just doesn't want to work out.

 

UpdateContext({vInTime:true}); Reset(ClockInTime)

 

 

Ok @SandraAkujobi 

I think the only solution to this is as below - can you please consider following exactly what is done here including the naming of the controls, card and form. If you want to use other names, replace them in the code with your names.

Firstly, it looks like this.

ClockIn.gif

 

 

 

 

 

The button must be in the card

The field names I have used are as below

ClockInFields.pngThe Default on the card (named ClockInDateCard here) - replace with the name of your field if different.

ThisItem.ClockInDate

The OnSelect of the ClockInButton is

UpdateContext({vInTime:true});
Reset(ClockInDay);
Reset(ClockInHour);
Reset(ClockInMinute);
SubmitForm(TimeForm);
UpdateContext({vInTime:false})

This sets the time, writes the data to the list and disables the button. If you open the form again with a date already there, it will be disabled.

The DisplayMode of the ClockInButton is

If(
    IsBlank(ClockInDay),
    DisplayMode.Edit,
    DisplayMode.Disabled
)

The DefaultDate of ClockInDay is

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

The Default of ClockInHour is

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

The Default of ClockInMinute is

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

I believe this solution will work for you

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

 

View solution in original post

@SandraAkujobi ,

Another thought that might suit - if you are not inputting into the fields other than from the button, there is a much simpler process of deleting them all from the card and replacing with a single text box. It was actually the solution I proposed at the beginning - it is not difficult and happy to document that as well if you want it.

@WarrenBelz That would be great actually cause I might use sometime in the future so it would be great to have it, thank you so much.

@WarrenBelzIt worked!! Thank you so much for putting up with this task, couldn't have done it without your help.

Thanks @SandraAkujobi ,

I will post this later on this thread.

OK @SandraAkujobi ,

Now to the probably easiest solution

Delete everything out of the card except the label, and put in a Text Input. I will show you it working firstClockInSingle.gif

 

 

 

 

Here is the structure as before

ClockInSingle.png

 

 

 

ClockInButton - OnSelect

UpdateContext({vInTime:true});
Reset(ClockInTime);
SubmitForm(TimeForm);
UpdateContext({vInTime:false})

ClockInButton - DisplayMode

If(
    IsBlank(ClockInTime),
    DisplayMode.Edit,
    DisplayMode.Disabled
)

 ClockInTime - Default

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

ClockInTime - DisplayMode

If(
    IsBlank(ClockInTime),
    DisplayMode.Edit,
    DisplayMode.View
)

I have added this - it puts the date in View mode as well as disabling the button so the date cannot be altered again.

Now the important addition - ClockInDateCard - Update

DateTimeValue(ClockInTime.Text)

 This is probably a much better look for your staff.

View solution in original post

Hey! @WarrenBelz

I have a question about your solution. I have done everything you told to build it with a text field. What do I need to insert in the on select of the reset button? So when a employe has pressed the clock in button he has a way back if he made a mistake.

 

In starttijd there is the following formula: If(vInTime1;Now();Parent.Default)

Wizkid_A_0-1604929275054.png

 

And in my SharePoint list there is a time difference of "-9", how can I fix this?

Wizkid_A_1-1604931107283.png

 

 

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Microsoft Ignite 768x460.png

Find your focus

Explore the latest tools,training sessions,technical expertise, networking and more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,557)