Posts

Showing posts from December 8, 2018

How to calculate time outside of work hours

Image
up vote 5 down vote favorite This seemed pretty straight forward initially, but has proved to be a real headache. Below is my table, data, expected output and SQL Fiddle of where I have got to in solving my problem. Schema & Data: CREATE TABLE IF NOT EXISTS `meetings` ( `id` int(6) unsigned NOT NULL, `user_id` int(6) NOT NULL, `start_time` DATETIME, `end_time` DATETIME, PRIMARY KEY (`id`) ) DEFAULT CHARSET=utf8; INSERT INTO `meetings` (`id`, `user_id`, `start_time`, `end_time`) VALUES ('0', '1', '2018-05-09 04:30:00', '2018-05-09 17:30:00'), ('1', '1', '2018-05-10 06:30:00', '2018-05-10 17:30:00'), ('2', '1', '2018-05-10 12:30:00', '2018-05-10 16:00:00'), ('3', '1', '2018-05-11 17:0...