I am trying to select today's events( fullcalendar
) from PHP and MySQL , for which I use the following code:
SELECT * FROM agenda.event
WHERE event.start_event = CURRENT_DATE()
AND event.end_event = CURRENT_DATE()
Now inside my table I have data like the following:
______________________________________________________
id title start_event end_event
_______________________________________________________
1 evento1 2019-06-11 10:00:00 2019-06-11 12:00:00
2 evento2 2019-06-11 13:00:00 2019-06-11 15:00:00
3 evento3 2019-06-12 08:00:00 2019-06-12 10:00:00
4 evento4 2019-06-13 08:00:00 2019-06-13 10:00:00
For this case, I should only get today's, that is, the first 2
eventos(2019-06-11)
, but no event returns.
Thanks in advance
Another possibility, as long as your columns are of type
datetime
, is to use the clauseBETWEEN
:datetime
adate
to compare them withCURRENT_DATE()
Edition
Possible solution
CURRENT_DATE()
returns a value inYYYY-MM-DD
for example:2019-06-12
and you are using it to compare with fields of typeDATETIME()
that is, that includehh:mm:ss
of type `2019-06-12 15:12:00.Exhibit:
Use
INTERVAL 1 DAY
to indicate that subtract one day from the date it returnsCURRENT_DATE()
and thus obtain the values sought.The possible solution is to pass the
start_event
y columnsstart_end
through the function to only get the dateDATE()
values and ignore the TIME part of the record.QUERY