Calculate hours

Hi , I have two complicated question ,

1- Let’s say a teacher check in to school at 2/1/2023 , 7:00 am – and check out at 2/1/2023 , 2:00 pm
so he worked 8 hours , and he did this for a month , I want to sum all the hours he worked for the hole month , How ?

2- What’s the best data setup for this ?
what I did is created two field on User datatype :

1- Check-in-time - List of date
2- Check-out-time - List of date

did I do this right ?

Hi there, @josemazin77… if I was doing what you described, I would probably do it in a way that looks something like the following.

First, I would create a Shift data type that looks like this.

Then, I would add a field to the User data type called something like current shift, and that field would have a field type of the Shift data type.

Now, let’s say we have a button labeled Start Shift. This button would have a workflow that looks like this.

At this point, we have a created a new shift for the current user, and we have populated the user’s current shift field with the newly-created shift.

Now, let’s say we have a button labeled End Shift. This button would have a workflow that looks like this.

At this point, we have updated the user’s current shift with an end time, and we have calculated the total hours for the shift.

Finally, a text element with the following expression would show the user’s total hours for the current month.

Anyway, you obviously don’t have to do it exactly like I showed, but hopefully this example will help you get down a good path.

Best…
Mike

3 Likes

so the hours will be saved , let’s said until this moment he worked 50hours/month

but I want to show the hours for only last two weeks it will show 25 hours right ?

Yes, the hours are saved, and if the user has worked 25 hours over the past two weeks and you change the constraint to sum the hours for the past two weeks, then yes, it will show 25 hours.

then thank you man very much , you saved my life :heart:

1 Like

Hi again sorry to bothering you

but if I want to show the time in and time out and hours in specific day - just one day -

should I do :

time in = date/time picker value
time out = date/time picker value
hours = date/time picker value

Try this…

I am using the creation date of the shift because I assume shifts are created on the actual days when they occur. You could also use the time in or time out field to get the same result.

Hi again I hope you doing okay
I did your way and it’s work perfect thank for that , I just have one little problem , I want the check in/out - in one button like the image below

image

but how I can make it - when user is checked in today and click it again this time he will check out -

because if I make two button and the user could click the wrong button and also it’s look perfect in one button

You can create two workflow events (events, not actions within the same event) for that button. The first event will run an action to check the user in only when the count of a search for a shift for the user on the current day that doesn’t have an end time is 0. The second event will have a similar condition on it, but the count will be greater than 0, and the action within the event will check the user out.

1 Like

Can you do it and send me a screenshot if you don’t mind , I didn’t know how to write this on bubble language :heart:

Hi mike

did I do this on the right way ?

image

image

the seconde event is :

image

Give this a go… create two workflow events (not custom events) like what I am showing below. The one I am showing will create a new shift for a user if they don’t already have a shift on the current day.

The workflow event on the left is the same, except the count in the condition is greater than 0, and the action inside the event will make changes to the current day’s existing shift instead of creating a new shift.

Make sense?

Edit: after looking back at my initial reply in this thread, the conditions I described above can be a lot simpler if you are using the current shift field on the User data type. If you are using that field, the condition I am showing can simply be Current User's current shift is empty. In that workflow, create a new shift, and in the next step, set the user’s current shift field to the result of step 1. Then, the condition on the other workflow would be Current user's current shift is not empty. That workflow will make changes to the Current user's current shift, and the change to make is to update the shift’s time out field with the current date/time. Finally, have a second step in that workflow that sets the current user’s current shift field to empty, and you should be good to go.

it’s works perfect , I appreciate your effort really , and actually I make it two button looks better , any problem never stop showing up , the problem is :

  • when Me As Parent check in two kids at 8:30 AM and then I came back and I checked out only one kid at 10 AM , and then came back and checked out the other one at 11 AM
    in the data both will showing checked out at 11 AM

How can I show every student checked out

NOTE : STUDENT ARE NOT A USER

have a good day …

It depends on how you are identifying students in the app. Because a parent can be checking in or checking out more than one student, you have to somehow specify the student who is being checked in or out. Without knowing all of the details of your app, there is no way I can be more specific than that.

in the shift datatype I make it like this , so I can know who check in and who check out , and please if you can tell me what kind of data you want to know , I’ll be happy to share screenshot with you

image

I would get rid of the list fields and have a student field that links to the Students data type. When a shift is created (i.e., when a student is checked in), populate the student field with the related student’s thing in the Students data type. When a student is checked out, find the shift that is related to that student and populate the time-out field.

Oh, and given the additional information in your latest question, you can’t use the current shift concept that I described earlier in this thread.

but the problem if parent want to check in kid , he can’t check more than one kid in the same time , right ?
he has to do the same process numerous time depending on number of student they have

You can make a user interface that enables a parent to check in multiple kids at the same time, but no matter how you do it, you should create a separate thing in the Shift data type for each kid.

So to do this interface I need to create state wit field List of student , right ?

I can’t tell you how to build your user interface, but a state with a list of students shouldn’t be necessary depending on the interface.