Reputation: 49
I have the following code on my php page to show events from mysql database that start today:
SELECT *
FROM events
WHERE DATE_FORMAT(sort_date, '%Y-%m-%d') >= Date_Format(Now(), '%Y-%m-%d')
AND authorize = 1
ORDER BY sort_date ASC
It is only showing calendar events starting TODAY, not yesterday or last week and this code is working nicely.
Some events have a longer duration than 24 hours, so we would like the event to not show "after" the end_date
So in essence, it shows only events starting NOW and stops showing after the end_date.
Any help on changing the code to keep an event until the end date would be appreciated.
Thanks
Upvotes: 2
Views: 58
Reputation: 108676
Assuming that your events
rows have a sort_date
and an end_date
in them, here's what you need.
SELECT whatever
FROM events
WHERE sort_date >= CURDATE()
AND end_date < CURDATE() + INTERVAL 1 DAY
etc etc etc
The expression < CURDATE() + INTERVAL 1 DAY
chooses all items for which the end_date is sometime up until, but not including, the first moment of tomorrow.
Notice that you don't need all that stuff with DATE_FORMAT()
that you showed in your question; you can do comparisons directly on dates.
Upvotes: 0