tjyoung
asked on
Display 3 months ago time span taking into account not all months are 31 days... how?
I'm trying to determine how to display the following:
2012-01-01 (which is 3 months ago on the first of the month excluding the current month we're in)
My code below (which I'm certainly not married to if there is a better way), does the above
Problem is I also need to show the last day of the month, 3 months ago, taking into account not all months have 31 days??
How do you accomplish that?
2012-01-01 (which is 3 months ago on the first of the month excluding the current month we're in)
My code below (which I'm certainly not married to if there is a better way), does the above
Problem is I also need to show the last day of the month, 3 months ago, taking into account not all months have 31 days??
How do you accomplish that?
$monthdate = date("Y-m");
$threemonth = strtotime ( '-3 month' , strtotime ( $monthdate ) ) ;
$threemonth = date ( 'Y-m' , $threemonth );
echo $threemonth."-01";
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That was all I actually needed to complete afterall.
thanks.
thanks.
I'm not 100% if this will work correctly.
This should display 2012/1/31. Current month -2 and then back one day...
This should display 2012/1/31. Current month -2 and then back one day...
$threemonthsago = mktime(0,0,0,date("m")-2,-1,date("Y"));
echo date("Y/m/d", $threemonthsago);
ASKER
thats great, shows me 3 months ago on the 1st of the month, cleaner then my method for sure.
How can I get it to show the last day of the month regardless of how many days are in the month?