note 83391 added to function.date

From: Date: Fri, 23 May 2008 13:54:43 +0000
Subject: note 83391 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-139646@lists.php.net to get a copy of this message
/** * 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; } ---- Server IP: 213.246.42.8 Probable Submitter: 212.234.204.78 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/83391 Del: integrated -- https://master.php.net/note/delete/83391/integrated Del: useless -- https://master.php.net/note/delete/83391/useless Del: bad code -- https://master.php.net/note/delete/83391/bad+code Del: spam -- https://master.php.net/note/delete/83391/spam Del: non-english -- https://master.php.net/note/delete/83391/non-english Del: in docs -- https://master.php.net/note/delete/83391/in+docs Del: other reasons-- https://master.php.net/note/delete/83391 Reject -- https://master.php.net/note/reject/83391 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139646) next »