note 80693 added to function.strtotime
| From: | ian_channingathotmail at osu1 dot php dot net | Date: | Tue, 29 Jan 2008 13:35:02 +0000 |
| Subject: | note 80693 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135541@lists.php.net to get a copy of this message | ||
This code is for relative dates similar to the add date functionality that C# has. It allows for
negative values to substract dates.
/*pre: format is either 'd' for days,'m' for months or 'y' for years
length is the number of days/months/years
date_array is optional,format is getdate()
post: returns the integer value of the date with the added length
*/
function date_add($length,$format,$date_array=null){
$new_timestamp = -1;
$date = is_null($date_array)?getdate():$date_array;
switch(strtolower($format)){
case 'd':
$new_timestamp =
mktime(0,0,0,$date["mon"],$date["mday"]+$length,$date["year"]);
break;
case 'm':
$new_timestamp =
mktime(0,0,0,$date["mon"]+$length,$date["mday"],$date["year"]);
break;
case 'y':
$new_timestamp =
mktime(0,0,0,$date["mon"],$date["mday"],$date["year"]+$length);
break;
default:
break;
}
return $new_timestamp;
}
----
Server IP: 87.124.64.96
Probable Submitter: 80.177.39.98
----
Manual Page -- http://www.php.net/manual/en/function.strtotime.php
Edit -- https://master.php.net/note/edit/80693
Del: integrated -- https://master.php.net/note/delete/80693/integrated
Del: useless -- https://master.php.net/note/delete/80693/useless
Del: bad code -- https://master.php.net/note/delete/80693/bad+code
Del: spam -- https://master.php.net/note/delete/80693/spam
Del: non-english -- https://master.php.net/note/delete/80693/non-english
Del: in docs -- https://master.php.net/note/delete/80693/in+docs
Del: other reasons-- https://master.php.net/note/delete/80693
Reject -- https://master.php.net/note/reject/80693
Search -- https://master.php.net/manage/user-notes.php