M David M David - 1 year ago 94
PHP Question

Getting php to properly add days to date

I have a invoicing system that generates the next due date after the invoice is paid. My problem though is I want to generate the next invoice based on the date the last one was due, not when it was paid.

I'm familiar with adding days to the current date such as this:

$nextduedate = date('Y-m-d', strtotime("+30 days"));

Lets say the invoice was due on 2016-05-08 but it was paid on 2016-05-12
How would I get the system to add 30 days to my variable
which is being pulled from the database and set the next invoices due date 30 days from the prior?

Answer Source

Try this:

$nextduedate = ('Y-m-d', strtotime($duedate. ' + 30 days'));

That will format your date, then add 30 days to the old due date stored in a variable.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download