What is the best way to calculate anniversary billing monthly with different lengths
We want to charge for storage say starting June 1st to July 1st and if the customer stays longer than July 1st we charge another amount for the next month but July has 31 says
If all months had 30 days the system would work fine
is there a calculation or formula we can use to fix this issue?
How about
$$ \Delta M = 12 (Y - Y_0) + (M - M_0) + [D \ge D_0], $$
where $Y$, $M$ and $D$ are the current year, month and day numbers, $Y_0$, $M_0$ and $D_0$ are the year, month and day of the starting date, $\Delta M$ is the calculated number of months elapsed since the starting date (rounded up) and $[Q]$ is the Iverson bracket, i.e. $1$ if the condition $Q$ is true and $0$ otherwise.
In effect, $\Delta M$ is incremented by one at the start of the $D_0$-th day of each month, unless the month has less than $D_0$ days, in which case the increment happens at the start of the first day of the next month.