Log in
updated 11:29 AM UTC, May 4, 2016

How to increment and decrement days in PHP

  • Written by Madhu V Rao
  • Published in PHP


Its very easy to increment and decrement days in PHP.

Here is an example which provides ways to increment days/months/years in PHP

$date = date("Y-m-d");

//increment 2 days
$mod_date = strtotime($date."+ 2 days");
echo date("Y-m-d",$mod_date) . "\n";

//decrement 2 days
$mod_date = strtotime($date."- 2 days");
echo date("Y-m-d",$mod_date) . "\n";

//increment 1 month
$mod_date = strtotime($date."+ 1 months");
echo date("Y-m-d",$mod_date) . "\n";

//increment 1 year
$mod_date = strtotime($date."+ 1 years");
echo date("Y-m-d",$mod_date) . "\n";

 

Run yourself to check the results
Sample test Run (Current date = 2013-02-24):

 

2013-02-26   // increment 2 days
2013-02-22  //decrement 2 days
2013-03-24  // increment 1 month
2014-02-24  //increment 1 year

Powered by Bullraider.com
Follow Us on Twitter
Find Us on Facebook
Follow Us on Google
Follow Us on Pinterest