In MySQL Database i have a worker who has 1 year of leave days (about 360 days):

+--------+---------+---------+-------------+---------+-----------+
|ID_LEAVE|ID_WORKER| BEGIN_DATE          | END_DATE              |
+--------+---------+---------+---------+------------+------------+
| 4      |   26    |2019-03-19 07:00:00  |2020-03-19 15:00:00    |  
+--------+---------+---------+----------------------+------------+

When i I'm going to run below Mysql Command which calculates leave time without weekends and holidays (which I'll show in code snippet), then it shows about like that:

+--------+---------+---------+-------------+---------+----------+----------+
|ID_LEAVE|ID_WORKER| BEGIN_DATE          | END_DATE             |LEAVE TIME|
+--------+---------+---------+---------+------------+-----------+----------+
| 4      |   26    |2019-03-19 07:00:00  |2020-03-19 15:00:00   |838:59:59 |
+--------+---------+---------+----------------------+-----------+----------+

Which time 838:59:59 is about... 35 days.

I have a trouble with it. Is that possible to calculate exactly leave time (of 1 year in format HH:mm:ss)? Thank you in advance for any answer.

SELECT leaves.ID_LEAVE, 
leaves.ID_WORKER, 
workers.FNAME, 
workers.LNAME, 
leaves.BEGIN_DATE, 
leaves.END_DATE, 
TIME_FORMAT(SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(TIME(leaves.END_DATE), TIME(leaves.BEGIN_DATE))))), '%H:%i:%s') AS 'LEAVE TIME' 
FROM (SELECT ADDDATE('1970-01-01', t4 * 10000 + t3 * 1000 + t2 * 100 + t1 * 10 + t0) AS date_value 
FROM (SELECT 0 t0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t0, 
(SELECT 0 t1 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t1, 
(SELECT 0 t2 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t2, 
(SELECT 0 t3 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t3, 
(SELECT 0 t4 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t4) calendar 
INNER JOIN project1.leaves ON calendar.date_value BETWEEN DATE(leaves.BEGIN_DATE) AND DATE(leaves.END_DATE) 
INNER JOIN project1.workers ON leaves.ID_WORKER = workers.ID_WORKER 
WHERE NOT WEEKDAY(date_value) IN (5, 6) AND NOT DATE(date_value) IN (SELECT HOLIDAY_DATE FROM project1.holidays) 
GROUP BY ID_LEAVE;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.