php: strtotime 如何获得去年七月? (或其他特定月份)

标签 php date strtotime

如果现在是 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.

最佳答案

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

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

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

基于需要返回今年 7 月以及:
<?php
$returnValue = strtotime('july '. (date("n") >= 7 ? 'this' : 'last' ) .' year');

关于php: strtotime 如何获得去年七月? (或其他特定月份),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35314934/

相关文章:

r - 生成具有特定开始和结束日期的时间序列

php - 增加天数的问题

php - PDO - 插入数据库后获取行的最佳方式

php - 这个 PHP 正则表达式有什么问题?

javascript - 使用javascript更改部分链接

mysql - 如何将记录集限制为过去的日期

php - strtotime 不插入数据库

PHP 解码 JSON POST

javascript - 使用 JavaScript 或 jQuery 获取当前月份的第一个和最后一个日期

jquery - 使用 jQuery 的日期选择器突出显示特定范围内的日期