note 52595 deleted from function.mktime by derick

From: Date: Sun, 24 Sep 2006 11:59:37 +0000
Subject: note 52595 deleted from function.mktime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-117511@lists.php.net to get a copy of this message
Note Submitter: jemore at m6net dot fr ---- A date enumerator function. With this, you set a begin date and an end date (timestamp format), and it will call a user function stepping one day or one month. <?php define ('DATE_ENUM_DAY', 1); define ('DATE_ENUM_MONTH', 2); /* * enumerate a date and call a user function * dateBeginTS, dateEndTS : Timestamp date * callbackfunc : name of the php function to callback * this cb function receive 2 parameters : the current enumerated date (timestamp) and the $param parameter * step : DATE_ENUM_DAY or DATE_ENUM_MONTH * param : a user parameter */ function date_enumeration($dateBeginTS, $dateEndTS, $callbackfunc, $step, $param = NULL) { $cur = $dateBeginTS; while($cur <= $dateEndTS) { $callbackfunc($cur, &$param); if ($step == DATE_ENUM_DAY) { $cur = mktime( date('h', $cur), date('i', $cur), date('s', $cur), date('m', $cur), date('d', $cur) + 1, date('Y', $cur)); } else if ($step == DATE_ENUM_MONTH) { $cur = mktime( date('h', $cur), date('i', $cur), date('s', $cur), date('m', $cur) + 1, date('d', $cur), date('Y', $cur)); } else { die ('No step specified'); } } } /// SAMPLE USAGE function cb_test($timestamp, $param) { echo date('r', $timestamp), ' ', $param, "<br>\n"; } date_enumeration( mktime(0,0,0,1,1,2000), mktime(0,0,0,1,1,2002), 'cb_test', DATE_ENUM_DAY ); ?>

« previous php.notes (#117511) next »