Question

I have two tables, one with dates (like 2013-06-27 00:00:00), and another one with multiple time (00:00:00, 01:00:00 etc.). My goal is to fill another table with the combination of these two tables : I would like to have a table with all the possible time of all the day :

2013-06-27 00:00:00
2013-06-27 01:00:00
...
2013-06-27 23:00:00
2013-06-28 00:00:00
...

Sadly, MySQL does not understand this DATE_ADD request ((SELECT FROM), (SELECT FROM)) :

SELECT DATE_ADD((SELECT journee FROM dates) ,INTERVAL (SELECT TIME_FORMAT(debut_interval, '%H.%i') FROM horaires) HOUR_MINUTE)

Anyone has an idea to do that?

Kind regards,

Morphilos

Was it helpful?

Solution

Try ADDTIME function:
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_addtime

create table dates(
  d date
);

create table times(
  t time
);

insert into dates values ('2013-02-13'),('2013-06-15');

insert into times values ('10:00:05'),('13:05:00'),('16:25:30');

select addtime( d.d, t.t ) date_and_time
from dates d
cross join times t
order by d.d, t.t;

Demo --> http://www.sqlfiddle.com/#!2/0c994/2

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top