How to subtract N days from specific date in PHP

3 Answers

0 votes
$date = new DateTime('2016-06-13'); 
$date_s = $date->sub(DateInterval::createFromDateString('10 days'));
echo $date_s->format("Y-m-d H:i:sa");
 
/*
run: 

2016-06-03 00:00:00am 

*/

 



answered Jun 13, 2016 by avibootz
0 votes
$date = new DateTime('2016-06-13'); 
$date->sub(new DateInterval('P10D'));
echo $date->format('Y-m-d')
 
/*
run: 

2016-06-03 

*/

 



answered Jun 13, 2016 by avibootz
0 votes
$date = new DateTime('2016-06-13'); 
date_sub($date, date_interval_create_from_date_string('10 days'));
echo date_format($date, 'Y-m-d');
 
/*
run: 

2016-06-03 

*/

 



answered Jun 13, 2016 by avibootz

Related questions

1 answer 136 views
136 views asked Mar 30, 2022 by avibootz
1 answer 97 views
1 answer 142 views
2 answers 227 views
227 views asked Jun 13, 2016 by avibootz
1 answer 186 views
1 answer 132 views
...