简体   繁体   中英

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 $dueDate which is being pulled from the database and set the next invoices due date 30 days from the prior?

Use DateTime() :

$dueDate = new DateTimeImmutable('2016-05-08');
$nextInvoice = $dueDate->modify('+30 days');
echo $nextInvoice->format('Y-m-d');

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM