note 51025 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 11 Jun 2006 11:32:43 +0000 |
| Subject: | note 51025 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114222@lists.php.net to get a copy of this message | ||
Note Submitter: roberta at lexi dot net
----
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