I’m stuck with a code. I want to see witch events from a MySQL database are before, after and during an inputted event.
I have a table with the following fields:
Event_id(int AUTO_INCREMENT)start_date(date)start_time(varchar)end_date(date)end_time(varchar)
The start time and end time are in 24 hrs time format, and are stored without the colon separator : (so 23:50 will be stored as 2350, and 1:00 will be stored as 0100)
The dates and time of the inputted event will be in the same formats.
How can I make a query (or script) that get the event that is the closest to the inputted event, a query that check if there are events during the inputted event and a query that get the event closest after the inputted event?
First off, start out by changing your scheme, so you instead have
For your queries, you can now use
TIMEDIFF.Closest event
That will get you the next event.
Events during event
That will give you events that are in progress.
You might need to wrap your
TIMEDIFFs inSECONDS()before doing the comparison.