note 103466 added to function.date
| From: | manchesterboy at gmail dot com | Date: | Thu, 14 Apr 2011 16:29:32 +0000 |
| Subject: | note 103466 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-178848@lists.php.net to get a copy of this message | ||
a simple method to work out future dates from a given one.
/**
* Handles a date in the format YYYYMMDD.
*
* Doesn't take a genius to modify it to use some other format.
* We provide either of the following units:
* 'h' -> 'hour', 'i' -> 'minute', 's'
-> 'second',
* 'm' -> 'month','d' -> 'day' , 'y'
-> 'year'
*/
public static function getNextDate($date, $amount, $unit='d'){
$dividers = array(' ', ':', '_', '-', '/',
'|');
$date = str_replace($dividers, '', $date);
$unit = strtolower($unit);
list($y, $m, $d) = array(substr($date, 0, 4), substr($date, 4, 2), substr($date, 6));
list($h, $i, $s) = array(1, 0, 0);
$x = substr($unit, 0, 1);
$$x += $amount;
return date('Ymd', mktime($h, $i, $s, $m, $d, $y));
}
----
Server IP: 69.147.83.197
Probable Submitter: 81.43.246.130
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/103466
Del: integrated -- https://master.php.net/note/delete/103466/integrated
Del: useless -- https://master.php.net/note/delete/103466/useless
Del: bad code -- https://master.php.net/note/delete/103466/bad+code
Del: spam -- https://master.php.net/note/delete/103466/spam
Del: non-english -- https://master.php.net/note/delete/103466/non-english
Del: in docs -- https://master.php.net/note/delete/103466/in+docs
Del: other reasons-- https://master.php.net/note/delete/103466
Reject -- https://master.php.net/note/reject/103466
Search -- https://master.php.net/manage/user-notes.php