How do I minus one month from Year-Month 2019-03 How do I minus one month from Year-Month 2019-03 codeigniter codeigniter

How do I minus one month from Year-Month 2019-03


You can try the following solution:

date('Y-m', strtotime($payroll['month'] . ' - 1 month'))


Try this -

echo $newdate = date('Y-m', strtotime('-1 months', strtotime($payroll['month'])));


So many nice answers here.

Just note that this can be done with PHP's DateTime class.

$date = new DateTime("2019-03-03");$date->sub(new DateInterval('P1M')); // P -> Period 1 Monthecho $date->format("Y-m")// Outputs: 2019-02

A quick note from strtotime() 's official documentation.

Note: Using this function for mathematical operations is not advisable. It is better to use DateTime::add() and DateTime::sub() in PHP 5.3 and later, or DateTime::modify() in PHP 5.2.