Pregunta

I am trying to calculate number of days in a billing cycle and the number of days left in a billing cycle. I have a value (i.e., 5) which represents the billing date every month (the 5th of every month in this case). I need a way to:

a. Calculate the number of days between the 5th of this month and the 4th of the following month

b. Calculate the number of days between today and the 4th of next month

Where I keep getting stuck is, let's say, today is the 3rd of the month. Well the 5th of this month hasn't happened yet so the calculation would need to look back to the 5th of last month (which will ultimately calculate that there are two days left in the billing cycle). Can I get some help how to property calculate this? I'm sorry I don't have any code snippets to post - every combination of mktime / date / strtotime I try fails miserably so I don't have anything helpful to put up.

Thank you!

¿Fue útil?

Solución

Your question is hard to understands and your explanation doesn't make it easier, but it seems that you have a certain date X (which is known completely, with day, month and year), and the next n-th day of the month.

Assume you have $d, $m, $y (day, month, year of current date) and $n (billing on n-th day). You can use "date()" to extract the parts if you don't have them split yet.

If $d > $n, then you will bill them next month. If $d < $n, it will be this month. If $d == $n billing is now or next month, your choice.

Adding a month (remember to correctly handle December) will give you the billing date, and you can calculate the difference.

Alternatively, just add a day to the current date in a loop until you hit the billing date...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top