note 52595 added to function.mktime
| From: | jemore at m6net dot fr | Date: | Fri, 06 May 2005 17:39:56 +0000 |
| Subject: | note 52595 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89010@lists.php.net to get a copy of this message | ||
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
);
?>
----
Manual Page -- http://www.php.net/manual/en/function.mktime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52595
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52595&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52595&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52595&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52595&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52595&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52595&report=yes
Search -- http://master.php.net/manage/user-notes.php