简体   繁体   中英

Strtotime php with date to start

Ok, it's works:

date('Y-m-d H:i:s', strtotime("+ 30 day"))

But, if I to use a date defined, how can I do? example:

date('2015-04-27', strtotime("+ 30 day"))

Thanks!

I don't know what you are trying to do here, but if you are asking how you would go about adding 30 days to a specific date you could do it in one of these ways:

<?php
$today = '2015-04-27';
$plusThirtyDays = strtotime($today . ' + 30 days');
echo date('Y-m-d H:i:s', $plusThirtyDays); // 2015-05-27

Or this way:

<?php
$today = new DateTime('2015-04-27');
$plusThirtyDays = new DateInterval("P30D");
$today->add($plusThirtyDays);
echo $today->format('Y-m-d'); // 2015-05-27

Checkout the docs below:
date
strtotime

DateTime
DateInterval

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