Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate time diffrence [duplicate]

I have two input type time. 1. time of entry 2. time of exit

Example 1:

Start: 00:00 end: 01:30 result: 1.5

Example 2 :

Start: 14:00 end: 00:00 result: 10

How to create an algorithm that calculates how many employees were at work? This number will be multiplied by the rate he earns. e.g. hours * rate (1.5 * 15)

like image 991
Vuzii Avatar asked Mar 18 '26 12:03

Vuzii


1 Answers

I'd count work time in seconds cause its much clearer and fairy.

// Example data
const secondsWorked  = 4321;
const rate = 15;

const secondsInHour = 3600;

const hoursWorked = secondsWorked / secondsInHour;
// Output: 1.2002777777777778
console.log("Hours worked: ", hoursWorked);

// Output: 18.0041666666666...
const income = hoursWorked * rate;
console.log("Calculated income: ", income);
like image 116
dan-maximov Avatar answered Mar 20 '26 01:03

dan-maximov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!