date("Y-m-d",strtotime("-1 month")) 真的靠谱吗?
时常用date("Y-m-d",strtotime("-1 month"))
获取上个月的日期,其实它并不靠谱。
如当前日期未3月3,则:var_dump(date("Y-m-d", strtotime("-1 month", strtotime("2018-03-31"))));
得到的结果并非2018-02-28而是2018-03-03
正确的方式之一是添加last day of
first day of
:var_dump(date("Y-m-d", strtotime("last day of -1 month", strtotime("2017-03-31"))));