note 80693 deleted from function.strtotime by derick

From: Date: Sun, 03 Aug 2008 11:56:17 +0000
Subject: note 80693 deleted from function.strtotime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-143121@lists.php.net to get a copy of this message
Note Submitter: ian _ channing at hotmail ---- This code is for relative dates similar to the add date functionality that C# has. It allows for negative values to substract dates. <?php /*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; } ?>

« previous php.notes (#143121) next »