Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP subtract 1 month from date formatted with date ('m-Y')

I'm trying to subtract 1 month from a date.

$today = date('m-Y'); 

This gives: 08-2016

How can I subtract a month to get 07-2016?

like image 374
Grant Avatar asked Aug 03 '16 08:08

Grant


People also ask

Can you subtract dates in PHP?

The date_sub() function subtracts some days, months, years, hours, minutes, and seconds from a date.

How can I get 30 days from date in PHP?

php $next_due_date = date('y-m-d',strtotime('+30 days',strtotime('echo $userRow3["due_date"]'))) .

What does date () do in PHP?

The date/time functions allow you to get the date and time from the server where your PHP script runs. You can then use the date/time functions to format the date and time in several ways.

How can I get first date and date of last month in PHP?

php echo 'First Date = ' . date('Y-m-01') . '<br />'; echo 'Last Date = ' . date('Y-m-t') .


1 Answers

 <?php    echo $newdate = date("m-Y", strtotime("-1 months")); 

output

07-2016 
like image 154
Passionate Coder Avatar answered Oct 11 '22 08:10

Passionate Coder