I have an up to date mysql database installation and I need a function to calculate the sales between the nth of the last month and today. The function will be called several times per day because I'm looking for the point at which the cumulative sales since the previous nth of the month cross a threshold.
The background is that I am developing a subscription site. Customers will sign up on ad-hoc days of the year and make purchases throughout the year. I want to be able to calculate the sales on the month-to-date basis.
If a customer signs up on the nth of the month then I need to calculate the sales between the previous nth of the month and today.
If the customer signs up on the 28th and today is the 30th then you'd think that there had only been 2 days of sales but if today is 30th March then it's been 30 days. In another example: if the customer signs up on Oct 31st how would this handle Feb 28th or April 30th?
I've looked at functions such as timestampdiff() but can not figure out a practical solution. By that I mean one that will do the job and can do the task efficiently without costing toooo many cpu cycles.
Thanks in anticipation