I a have table in mysql with some data like this:
id from to
---- -------------------- ---------------------------
1 2013-01-31 23:50:00 2013-02-02 09:00:00
2 2013-02-05 11:21:12 2013-02-08 01:01:01
3 2013-02-08 17:33:44 2013-02-08 18:22:55
4 2013-02-12 01:40:12 2013-02-12 02:00:59
5 2013-02-28 01:40:12 2013-03-02 02:00:59
I need a Mysql query or a php code for finding difference between 'from' column and 'to' column of each rows, and find how many seconds are there in each day between 'from' and 'to' date separately, for example for row 1 the needed output be something like this:
difference between 2013-01-31 23:50:00 - 2013-02-02 09:00:00 for row 1
2013-01-31 : 600 sec (24:00:00 - 23:50:00 => 600 sec)
2013-02-01 : 86400 sec (24:00:00 - 00:00:00 => 86400 sec)
2013-02-02 : 32400 sec (09:00:00 - 00:00:00 => 32400 sec)
and so on ... for each row
MySQL command is preferred. which code can create this output? is there any specific function in php or mysql for creating this output?
I read these answers: mysql calculate seconds between two date/times for each day
MySQL: how to get the difference between two timestamps in seconds
but these are not my answer.
for information: link 1 is a question like my question but the answer is not true because "The command needs grouped by day" but how?! and the second is not my question but question one marked as duplicated with link 2 and it is not true.