【问题标题】:php: strtotime how to get last july? (or other specific month)php: strtotime 如何得到去年七月? (或其他特定月份)
【发布时间】:2016-02-10 12:11:53
【问题描述】:

如果现在是 2016-02-10 我需要返回 2015-07-01(或 2015-07-10)

strtotime('july'); // returns 2016-07-10
strtotime('last july'); // does not work
strtotime('july 2015'); // I have not '2015' for query. 
//Only if compare date (month) now and month needed. In looks not realy straight way.

【问题讨论】:

    标签: php date strtotime


    【解决方案1】:

    如果您今年过了七月会怎样?那么它是否需要在 2016 年 7 月返回,还是总是前一年?

    如果是这样,您可以使用“去年七月”:

    <?php
    $returnValue = strtotime('july last year');
    

    基于今年7月也需要返回:

    <?php
    $returnValue = strtotime('july '. (date("n") >= 7 ? 'this' : 'last' ) .' year');
    

    【讨论】:

    • 是的,如果我过了 7 月或正中,则需要 2016 年 7 月
    • 抱歉,我认为一位同事不小心点击了反对票,我没有意识到,所以我无法撤消。这实际上很有帮助,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多