So if today was April 12, 2010 it should return October 1, 2009
Some possible solutions I've googled seem overly complex, any suggestions?
So if today was April 12, 2010 it should return October 1, 2009
Some possible solutions I've googled seem overly complex, any suggestions?
use a combination of mktime and date:
$date_half_a_year_ago = mktime(0, 0, 0, date('n')-6, 1, date('y'))
to make the new date relative to a given date and not today, call date with a second parameter
$given_timestamp = getSomeDate();
$date_half_a_year_ago = mktime(0, 0, 0, date('n', $given_timestamp)-6, 1, date('y', $given_timestamp))
to output it formatted, simply use date again:
echo date('F j, Y', $date_half_a_year_ago);
A bit hackish but works:
<?php
$date = new DateTime("-6 months");
$date->modify("-" . ($date->format('j')-1) . " days");
echo $date->format('j, F Y');
?>
Hm, maybe something like this;
echo date("F 1, Y", strtotime("-6 months"));
EDIT;
if you would like to specify a custom date use;
echo date("F, 1 Y", strtotime("-6 months", strtotime("Feb 2, 2010")));