<button id="g80sy"></button>
  • <abbr id="g80sy"></abbr>
  • <button id="g80sy"></button>
    <rt id="g80sy"><delect id="g80sy"></delect></rt>
  • PHP strtotime小BUG

    程序猿 2021-07-31 16:37:11 1896瀏覽 加載中

    今天看網(wǎng)站統(tǒng)計發(fā)現(xiàn)上月和這月的數(shù)據(jù)一樣。用的whereMonth 時間查詢

    ->whereMonth('create_time')  // 本月
    ->whereMonth('create_time','last month')  // 上月

    看著代碼沒啥問題,往上翻找到了

            if (in_array($month, ['this month', 'last month'])) {
                $month = date('Y-m', strtotime($month));
            }

    于是打印了

    dump(date("Y-m-d",strtotime("this month")));
    dump(date('Y-m-d', strtotime("last month")));

    結(jié)果

    ^ "2021-07-31"
    ^ "2021-07-01"

    這不是同一月么。這是strtotime函數(shù)的BUG吧。在31號的時候返回不到上一月。

    在網(wǎng)上巴拉巴拉,發(fā)現(xiàn)可以這樣寫

    dump(date("Y-m-d",strtotime("first day of this month")));
    dump(date('Y-m-d', strtotime("first day of last month")));

    結(jié)果

    ^ "2021-07-01"
    ^ "2021-06-01"

    這樣就能返回到上一個月了。

    標簽:
    最后修改:2025-05-30 00:26:53

    非特殊說明,本博所有文章均為博主原創(chuàng)。

    主站蜘蛛池模板: 娄烦县| 磐安县| 昌邑市| 新源县| 滁州市| 醴陵市| 阆中市| 信宜市| 盈江县| 高邮市| 射阳县| 余庆县| 丹东市| 富蕴县| 正镶白旗| 元谋县| 青岛市| 大关县| 亚东县| 兴和县| 林口县| 互助| 英山县| 东方市| 遂川县| 台南县| 炎陵县| 额尔古纳市| 廊坊市| 临朐县| 茂名市| 贵溪市| 白河县| 徐汇区| 铁力市| 富裕县| 囊谦县| 裕民县| 永修县| 二连浩特市| 临沧市|