There are some solutions, but i don't know how to change that for my table. So i hope someone could help me.
I have the following Table
╔═════╦═════════╦════════════╦════════════╦═══════════╗
║ UID ║ TITLE ║ BEGIN ║ END ║ RECURRING ║
╠═════╬═════════╬════════════╬════════════╬═══════════╣
║ 1 ║ event A ║ 1359741600 ║ 1359745200 ║ none ║
║ 1 ║ event B ║ 1359741600 ║ 0 ║ daily ║
║ 1 ║ event C ║ 1359741600 ║ 0 ║ weekly ║
║ 1 ║ event D ║ 1359741600 ║ 0 ║ monthly ║
║ 1 ║ event E ║ 1359741600 ║ 0 ║ yearly ║
╚═════╩═════════╩════════════╩════════════╩═══════════╝
How can i now select every event from now on up to 7 days and also all recurring events in the next 7 days?
The following i've tried but not working very good and not finished.
SELECT
*
FROM
`tx_events_domain_model_event`
WHERE
/* none recurring events in the next 7 days */
(
recuring = 'none'
AND (begin_date + begin_time) >= UNIX_TIMESTAMP(NOW())
AND (end_date + end_time) <= UNIX_TIMESTAMP(DATE_ADD(NOW(), INTERVAL 7 DAY))
)
OR
/* Daily */
recuring = 'daily'
OR
/* Weekly */
(
recuring = 'weekly'
AND DAYOFWEEK(NOW()) - 1 <= DAYOFWEEK(FROM_UNIXTIME(begin_date)) - 1
)
OR
/* Monthly */
(recuring = 'monthly'
AND
Found solution with help of fellow programmer Aaron Hanson. The issue is with daylight savings. Here is an updated query...
Here's something I've been playing with (and here it is as an sqlfiddle with some sample data)... not 100% sure about it, but it should grab the last 7 days of data. Note that I'm using MySQL
DATETIME
versus integer timestamps, but you should be able to convert that easily (for testing the query it was much easier to use string dates).Here is my code which I have used for my reminder table.
You can just pass your date in the function and it will find whether the seleted date has event or not. It will give your all events which is recurring event or non-recurring event.