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

前端 未结 4 1755
悲哀的现实
悲哀的现实 2021-01-01 09:09

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

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

4条回答
  •  攒了一身酷
    2021-01-01 10:00

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

提交回复
热议问题