【问题标题】:Get previous year start and end date in php在php中获取上一年的开始和结束日期
【发布时间】:2017-10-25 09:12:57
【问题描述】:

我可以通过以下方式获取上个月的开始和结束日期。

echo date("d-m-y",strtotime("first day of -1 month")); //output: 01-09-17
echo date("d-m-y",strtotime("last day of -1 month")); //output: 30-09-17

但我无法获得上一年的开始和结束日期。我尝试的代码如下。

echo date("d-m-y",strtotime("first day of -1 year")); //output: 01-10-16
echo date("d-m-y",strtotime("last day of -1 year")); //output: 31-10-16

我得到错误的输出。我需要输出为 01-01-1631-12-16。

任何帮助将不胜感激。提前致谢。

【问题讨论】:

    标签: php date date-format


    【解决方案1】:

    为什么不让它变得简单呢?
    一年的第一天和最后一天被称为“常数”。

    echo date("01-01-y",strtotime("-1 year")) ."\n";
    echo date("31-12-y",strtotime("-1 year"));
    

    https://3v4l.org/V0ktv

    【讨论】:

      猜你喜欢
      • 2012-03-12
      • 1970-01-01
      • 2017-03-02
      • 1970-01-01
      • 2021-04-12
      • 1970-01-01
      • 2022-12-11
      • 2018-10-05
      • 2021-12-29
      相关资源
      最近更新 更多