recover Datetime in Mysql between current date

Asked

Viewed 117 times

0

In my database I have 2 fields: "data_start and data_end". From a current Datetime, I need to select all dates that are in the range that date_time >= data_start AND date_time <= data_end. I did the following query and it didn’t work. (consider date_time as if it was '2014-10-14 17:44:00') Thank you!

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

1 answer

0

Put the data_fim as >=. The way you are doing, the query deletes all dates that are smaller or equal than 2014-10-14 17:44:00 and the remaining set, filters the records where the data_fim is larger 2014-10-14 17:44:00, that is, no record, because the ones left are all smaller or equal.

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

  • "UPDATE CAMPAIGN SET state = :new state_state WHERE state = :current state_state AND data_end >= now() AND data_start <= now()"; This is the original query. It worked perfectly, I was the one who misinterpreted the results.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.