首页 > 解决方案 > 试图从日期中删除 1 个月

问题描述

我在看别人的代码。基本上,该代码旨在提取本月的数据和前几个月的数据。

今天,它显示 7 月为当前月份,7 月为上个月。我怀疑是因为今天是 7 月 31 日,而不是 6 月 31 日。

下面是定义上个月的代码 - 有什么想法吗?

$this->monthPrev    = date('F Y', strtotime('this month -1 month'));
$this->currentMonth = date('F Y', strtotime('this month'));

标签: codeigniter

解决方案


要获取上个月的日期,请尝试以下操作:

echo date('F Y', strtotime(date('F Y')." -1 month"));

它将返回:

June 2019

示例片段


推荐阅读