note 83391 deleted from function.date by sobak

From: Date: Thu, 01 Dec 2016 13:46:33 +0000
Subject: note 83391 deleted from function.date by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207853@lists.php.net to get a copy of this message
Note Submitter: chubby at chicks dot com ---- <?php /** * Checks wether a date is between an interval * * Usage: * * // check if today is older than 2008/12/31 * var_dump(currentDayIsInInterval('2008/12/31')); * // check if today is younger than 2008/12/31 * var_dump(currentDayIsInInterval(null,'2008/12/31')); * // check if today is between 2008/12/01 and 2008/12/31 * var_dump(currentDayIsInInterval('2008/12/01','2008/12/31')); * * Will trigger errors if date is in wrong format, notices if $begin > $end * * @param string $begin Date string as YYYY/mm/dd * @param string $end Date string as YYYY/mm/dd * @return bool */ function currentDayIsInInterval($begin = '',$end = '') { $preg_exp = '"[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]"'; $preg_error = 'Wrong parameter passed to function '.__FUNCTION__.' : Invalide date format. Please use YYYY/mm/dd.'; $interval_error = 'First parameter in '.__FUNCTION__.' should be smaller than second.'; if(empty($begin)) { $begin = 0; } else { if(preg_match($preg_exp,$begin)) { $begin = (int)str_replace('/','',$begin); } else { trigger_error($preg_error,E_USER_ERROR); } } if(empty($end)) { $end = 99999999; } else { if(preg_match($preg_exp,$end)) { $end = (int)str_replace('/','',$end); } else { trigger_error($preg_error,E_USER_ERROR); } } if($end < $begin) { trigger_error($interval_error,E_USER_WARNING); } $time = time(); $now = (int)(date('Y',$time).date('m',$time).date('j',$time)); if($now > $end or $now < $begin) { return false; } return true; } ?>

« previous php.notes (#207853) next »