Search code examples
phpdatetimesubtraction

PHP: simplest way to get the date of the month 6 months prior on the first?


So if today was April 12, 2010 it should return October 1, 2009

Some possible solutions I've googled seem overly complex, any suggestions?


Solution

  • 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")));