Link to home
Start Free TrialLog in
Avatar of sasnaktiv
sasnaktivFlag for United States of America

asked on

If today's date is 2013-01-22, how can I get Last Month?

RE: date("Y-m-d");

My brain has turned to mush today.
Can anybody tell me how I can get 2012-12-01 when today's date is 2013-01-22?
Basically I'm looking for $LastMonth when this month is January.
Thanks,
Sas
Avatar of n2fc
n2fc
Flag of United States of America image

set day = 1; month=month-1; if month ==0 {year=year-1; month=12}
Avatar of sasnaktiv

ASKER

Thanks n2fc,
I don't understand how to apply that.
Can you give me a bigger picture?
Sas
ASKER CERTIFIED SOLUTION
Avatar of Frosty555
Frosty555
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Frosty,
That's perfect!

Ray, I'm only getting the month (12) and not the year (2012)
Thanks for the help and attention Guys.
Sas
PLEASE READ THE ARTICLE!  It's not rocket science but it requires a small investment of time and effort on your part.  The date() function has a formatting argument.  You simply have to understand the formatting argument to get the answers you want.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html