Skip to content

Instantly share code, notes, and snippets.

@anxp
Last active January 28, 2019 20:44
Show Gist options
  • Save anxp/4884bfd528ddee83ab706d2d233536ee to your computer and use it in GitHub Desktop.
Save anxp/4884bfd528ddee83ab706d2d233536ee to your computer and use it in GitHub Desktop.
A function to check if date/time is in acceptable interval.
<?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