retrieve DateTime in MySQL between current date

0

In my database I have 2 fields: "start_date" and "end_date". From a current DateTime, I need to select all dates that are in the range where date_time > = start_date AND date_time < = end_data. I did the following query and it did not work. (consider date_time as if it were '2014-10-14 17:44:00') Thanks!

SELECT * FROM campanha WHERE data_inicio <= '2014-10-14 17:44:00' AND data_fim > '2014-10-14 17:44:00';
    
asked by anonymous 15.03.2016 / 13:24

1 answer

0

Set data_fim to >= . In the way you are doing, the query excludes all dates that are less than or equal to 2014-10-14 17:44:00 and the remaining set, filters the records where data_fim is greater 2014-10-14 17:44:00 , ie no record, since the that are left are all smaller or equal than that.

Eg: SELECT * FROM campanha WHERE data_inicio <= '2014-10-14 17:44:00' AND data_fim >= '2014-10-14 17:44:00';

    
15.03.2016 / 14:23