Last active
January 28, 2019 20:44
-
-
Save anxp/4884bfd528ddee83ab706d2d233536ee to your computer and use it in GitHub Desktop.
A function to check if date/time is in acceptable interval.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//This function checks if specified date IS IN acceptable interval from NOW to some moment in the past. | |
//$date_to_check need to be in classic datetime format, like in mySQL; | |
//$interval sets like here http://php.net/manual/en/dateinterval.construct.php, but without 'P', | |
//'P' will be added automatically. | |
function is_date_acceptable($date_to_check, $interval) { | |
$now = new DateTime(); | |
$interval = 'P'.$interval; | |
$min_acceptable_date = $now->sub(new DateInterval($interval)); | |
$checking_date = new DateTime($date_to_check); | |
return (($checking_date > $min_acceptable_date) ? TRUE : FALSE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment