function Time_is_older_than ($t, $check _time) { $t = Strtolower ($t); $time _type = substr (preg_replace ('/[^a-z]/', ', $t), 0, 1); $val = Intval (preg_replace ('/[^0-9]/', ' ', $t)); $ts = 0; (s) econds, (m) inutes, (d) ays, (y) ears if ($time _type = = ' s ') {$ts = $val;} else if ($time _type = = ' m ') {$ts = $val * 60;} else if ($time _type = = ' h ') {$ts = $val * 60 * 60;} else if ($time _type = = ' d ') {$ts = $val * 60 * 60 * 24;} else if ($time _type = = ' Y ') {$ts = $val * 60 * 60 * 24 * 365;} else {die (' Unknown time Format given! ');} if ($check _time < (time ()-$ts)) {return true;} return false; } Examples of Use: Timestamp to test: (Could is from an database or something else) $time = 1146722922; Long If check: if (Time_is_older_than (' 30m ', $time)) { print ' The given timestamp: '. Date (' l DS \of F Y h:i:s A ', $time); Print "-is older than minutes \ n "; } else { print ' The given timestamp: '. Date (' l DS \of F Y h:i:s A ', $time); Print "-is not older than minutes \ n "; } Short Checks: if (Time_is_older_than (' 10s ', $time)) {print "is older than seconds \ n "; } if (Time_is_older_than (' 200m ', $time)) {print "is older than minutes \ n "; } if (Time_is_older_than (' 2h ', $time)) {print "is older than 2 hours \ n "; } if (Time_is_older_than (' 4d ', $time)) {print "is older than 4 days \ n "; } if (Time_is_older_than (' 1y ', $time)) {print "is older than one year \ n "; } |