I'm trying to build a calendar of reservations and are now stuck in an equation I do not get together.
The person who administers the calendar can create their own periods of the year when visitors have the opportunity to book. And these periods should now be synchronized with the calendar.
The periods are stored in the following columns in the database:
[from_month] - [from_day] - [to_month] - [to_day]
The calendar is built in PHP. And every day should be checked against the database if it is a valid day to book, according to the periods that are saved. So that date is within one period.
That's where I got stuck now. I thought it would just be to write:
WHERE from_month <= '".$this_monthnr."'
AND from_day <= '".$this_daynr."'
AND to_month >= '".$this_monthnr."'
AND to_day >= '".$this_daynr."'
But it does not work if, for example, the "from date" is 08-01 and the "end date" is 02-01. Then it becomes:
WHERE 08 <= '".$this_monthnr."'
AND 01 <= '".$this_daynr."'
AND 02 >= '".$this_monthnr."'
AND 01 >= '".$this_daynr."'
It becomes crazy as it's a year-end there between this dates, which makes the ending date value becomes lower than the start date. And the parameter [year] should not be included since these periods should be the same year after year, so it is not necessary.
Would be grateful if some genius wanted to help me. And if there is anything you have questions or do not understand what I mean, just ask.
The goal is that the SQL query should return the row represent the period in which the selected calendar day is within, if it exists. Otherwise, it should not return anything at all.