note 33680 added to function.date
| From: | tjw at tjw dot org | Date: | Thu, 03 Jul 2003 16:59:22 +0000 |
| Subject: | note 33680 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-51474@lists.php.net to get a copy of this message | ||
// dateadd($datestr, $num, $unit)
// $datestr is a string that strtotime() is able to parse
// $num is the number of units to add
// $unit is either "Y", "m", "d", "H", "i",
"s" as understood by date()
// returns a UNIX timestamp of the resulting date
function dateadd($datestr, $num, $unit) {
$units =
array("Y","m","d","H","i","s");
$unix = strtotime($datestr);
while(list(,$u) = each($units)) $$u = date($u, $unix);
$$unit += $num;
return mktime($H, $i, $s, $m, $d, $Y);
}
// Examples
// Add 5 days
echo date("Y-m-d H:i:s", dateadd("2003-04-12", 5, "d"));
// Test Leap Year
echo date("Y-m-d H:i:s", dateadd("2004-02-28 23:31:00", 30, "i"));
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33680
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33680&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33680&report=yes