note 51025 added to function.date
| From: | roberta at lexi dot net | Date: | Thu, 17 Mar 2005 01:18:47 +0000 |
| Subject: | note 51025 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86572@lists.php.net to get a copy of this message | ||
Here's an easy way to deal with date recurrences, or if you need to add days, months or years
to a current date...
<?php
//$type determines which set of variables will be selected below.
if ($type == 'daily'){ //daily
$increment = 1;
$stmt = 'days';
}
else if ($type == 'weekly'){ //weekly
$increment = 7;
$stmt = 'days';
}
else if ($type == 'biweekly'){ //bi-weekly
$increment = 14;
$stmt = 'days';
}
else if ($type == 'monthly'){ //every month
$increment = 1;
$stmt = 'months';
}
else if ($type == 'biannualy'){ //every 6 months
$increment = 6;
$stmt = 'months';
}
else{ //every year
$increment = 1;
$stmt = 'years';
}
//set counter
$t = $increment;
//will continue to loop as many times as the recurrence ($number_times_recurring)
while ($t<($number_times_recurring*$increment)){
//$calendar_startdate and $calendar_enddate are pre-determined and match the Y-m-d H:i:s format
$startdate = date("Y-m-d H:i:s", strtotime($calendar_startdate." + ".$t."
".$stmt));
$enddate = date("Y-m-d H:i:s", strtotime($calendar_enddate." + ".$t."
".$stmt));
//here you can complete a database "INSERT" or whatever you want to do
$t = ($t+$increment);
}
?>
I hope this helps! :)
Roberta
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51025
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51025&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51025&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51025&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51025&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51025&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51025&report=yes
Search -- http://master.php.net/manage/user-notes.php