在PHP中检查时间戳值是否在当前月份

时间:2016-03-17 09:41:31

标签: php date

我只是想知道,如何检查当前月份中的时间戳(任何月份,任何年份,任何日期)是否存在于PHP中?

For.eg 1456132659 这是一个示例时间戳,表示上个月的日期。我想要像

这样的条件
if(1456132659 is in current month) {
//true 
}
else {
//false
}

我该怎么做?

2 个答案:

答案 0 :(得分:3)

只需比较month -

即可
if(date('m', 1456132659) === date('m')) {
    //your code goes here
}

答案 1 :(得分:0)

首先需要使用以下PHP代码获取当月第一个和最后一个日期的时间戳 -

$first_minute = mktime(0, 0, 0, date("n"), 1);
$last_minute = mktime(23, 59, 0, date("n"), date("t"));

// Now just compare the timestamp for above two values by using below condition

if($timestamp >= $first_minute AND $timestamp <= $last_minute) {

    // Your line of code if condtion fullfill.

}