andresmijares
andresmijares

Reputation: 3744

date() to a integer php

I have to validate some values vs the last six hours, so let it like:

  $last_six_hours = (time() - (3600 *6));

If I have to compare vs a integer like 16hs, what is the best approach to do this?

Upvotes: 0

Views: 51

Answers (1)

John Conde
John Conde

Reputation: 219804

strtotime() takes relative amounts and returns a unix timestamp:

$four_o_clock = strtotime('16:00:00');
if ($sometimestamp > $four_o_clock) {
    // it happened after 16:00:00 today
}

Upvotes: 3

Related Questions