简体   繁体   中英

taking 3 and 4 days off current date not working

It is as simple as this really, I'm messing around with a few things and currently its to do with the date... so I have this...

$day = date('d',strtotime("+0 days"));
$month = date('M',strtotime("+0 days"));
$year = date('Y',strtotime("+0 days"));
$date = $day.'/'.$month.'/'.$year;

$echo $date;

and there is no problem with this. But messing around with it trying to add/takeaway days from it, that is when I get a problem. When Ii do this..

$day = date('d',strtotime("+1 days"));
$month = date('M',strtotime("+1 days"));
$year = date('Y',strtotime("+1 days"));
$date = $day.'/'.$month.'/'.$year;

again I get know problem and I can add how every many days, there's never an issue, when I take away days though, I can take 1,2,5,6,7,8,9 and so on.. days away but trying to take 3 or 4 days away, like ...

$day = date('d',strtotime("-3 days"));
$month = date('M',strtotime("-3 days"));
$year = date('Y',strtotime("-3 days"));
$date = $day.'/'.$month.'/'.$year;

it doesn't take that amount of days away, it just takes 1 away from the current date. Can anyone explain why this is happening? and why I cant get just take 3 & 4 days off the current date?

Try this

$now = date("d/M/Y");
$newDate = date("d/M/Y", strtotime('-3 day'.$now));

You can do all stuff in above one line instead of getting days, months separately.

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