siva nanda perumal
siva nanda perumal

Reputation: 153

Check the timestamp value is in current month or not in PHP

I just want to know, how to check the timestamp(any month, any year, any date) is present in the current month or not in PHP?

For.eg 1456132659 This is an example timestamp which indicates the last month date. I want a condition like

if(1456132659 is in current month) {
//true 
}
else {
//false
}

How can I do this?

Upvotes: 1

Views: 1093

Answers (2)

Mohneesh Agrawal
Mohneesh Agrawal

Reputation: 103

You first need to fetch the timestamp of first and last date of current month by using below PHP code-

$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.

}                         

Upvotes: 0

Sougata Bose
Sougata Bose

Reputation: 31749

Simply compare the month -

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

Upvotes: 3

Related Questions