I am setting up a recurring billing processor*. The client wants to be able to set that clients can choose the billing to occur fortnightly, aka every two weeks.
I could attempt to calculate the 'next' payment date myself, but it seems it would be much more reliable to record the first payment date, and then use an SQL query to calculate 'is today a 2 N weeks after the first date'.
select * from recurring_payments
where (datediff(first_billing_date, now() % 14) = 0
However that has the downside of doing a (presumably) unindexable full table scan. Is there a better way of finding rows for who a field matches 2N days ago?
This is in MySQL initially, but moving to MSSQL in a few weeks, so a generic method would be better than a bespoke feature.
*yes, I'm scared.