0

I have a mySQL table which contains events, details on the event, the event date and a recurring value - which is how often the event recurs in days.

e.g. Date: 2012-12-03, Recurrance: 7 - it will recurr every 7 days.

I am now looking to search on this by date and would like the row to be returned if the search was for 2012-12-03, 2012-12-10, 2012-12-17, 2012-12-24...+7 days.

Currently, the search is for a specific day:

SELECT 
    id, 
    title, 
    venue, 
    date_format(datetime, '%I:%i%p') AS time 
from 
    bt_db_eventcal 
WHERE 
    DATE(datetime) = '" . $date . "'

Can anyone help expand this to return rows based on the recurrance?

Thanks

1 Answer 1

1

its a simple math really. you subtract the saved date from the search date and mod the value by the recurrence. if the value is 0 then it is good.

Sign up to request clarification or add additional context in comments.

1 Comment

Excellent - thanks. The modified query is SELECT id, title, venue, date_format(datetime, '%I:%i%p') AS time from bt_db_eventcal WHERE DATEDIFF(DATE(datetime),'2012-12-10' % recurring=0 AND '2012-12-10'<=recur_until Forgot to mention there was a "recur_until" field too

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.