I’m creating a timesheet app for a simple punch-in/out. I created a calculation to calculate the hours worked based on clock-in and clock-out times. Here is the calculation:
you’re on the absolute correct path here - the only issue is that differenceInHours will only return the full hours “fitting” into the difference. If you’d like to get accurate decimal hours, you could use differenceInMinutes and then divide by 60.
@Luis here is my little code in similar context where you get only working days from Monday - Friday, exclude weekends so you can get how many working days is within month…
var i,day,
start = @In,
end = @Out,
dur = moment(end).diff(start,"d")+1,
count = 0;
for(i = 0; i < dur; i++){
day = moment(start).add(i,"d").isoWeekday();
if(day != 6 && day != 7){
count +=1; } };
count