function - How to get Dates of Previous or Next Months in PHP? -


i know date("y"), date("m") , date("d") return current year (2013), month (07) , date (11) respectively.

i working date format: "2013-07-11". have current date this. want value "2013-06-11" , "2013-08-11" somehow using php.

what might code values (last month's same date, , next month's same date)?

i tried:

$lastmonth = date ("m") - 1; $lastdate = date("y") . "-0" . $lastmonth . "-" . date("d"); 

but return error when october. in october show "2013-010-11".

what can better solution? can me?

use php's strtotime():

echo date('y-m-d', strtotime('+1 month')); //outputs 2013-08-11 echo date('y-m-d', strtotime('-1 month')); //outputs 2013-06-11 

Comments