Ziprian
Ziprian

Reputation: 11

Check whether a timestamp is older or newer than another

I have 2 Timestamps like 2015-06-26 17:43:18 and 2015-06-26 17:22:08.

How can I check whether the first timestamp is earlier than the second?

Upvotes: 0

Views: 413

Answers (1)

John Conde
John Conde

Reputation: 219814

Just use DateTime() objects which are comparable:

$date1 = new DateTime('2015-06-26 17:43:18');
$date2 = new DateTime('2015-06-26 17:22:08');
if ($date1 < $date2) {
    // $date1 is earlier than $date2
}

Demo

Upvotes: 2

Related Questions