note 100975 added to function.strtotime
| From: | elitezenithwebATexampleDOTcom at osu1 dot php dot net | Date: | Thu, 18 Nov 2010 06:24:38 +0000 |
| Subject: | note 100975 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174142@lists.php.net to get a copy of this message | ||
I hope that this function comes useful to someone.
<?php
function wdates($start = 0, $amount = 10, $format = 'Y', $interval = 'Y',
$decrease = true)
{
// Determining where we should start the dates (In years)
$start = ((is_numeric($start)) ? $start : 0);
// Accomidating the AMOUNT returned accordignly to the START
$amount += $start;
// Creating an array of years {$amount} times
for($i = $start; $i <= $amount; ++$i)
{
// Checking the interval to increase/decrease by
$int = (($interval == 'D') ? 'day' : (($interval == 'M') ?
'month' : 'year'));
// Checking if we are decreasing or increasing
$loop = (($decrease == true) ? '-' : '+');
// Creating the appropriate time stampe
$tmsp = strtotime($loop . $i . ' ' . $int);
// Building the date array
$date_arr[] = date($format, $tmsp);
}
// Returning the date array
return $date_arr;
}
print_r(wdates());
?>
That prints:
Array
(
[0] => 2010
[1] => 2009
[2] => 2008
[3] => 2007
[4] => 2006
[5] => 2005
[6] => 2004
[7] => 2003
[8] => 2002
[9] => 2001
[10] => 2000
)
While
<?php
print_r(wdates(12,7));
?>
Prints
Array
(
[0] => 1998
[1] => 1997
[2] => 1996
[3] => 1995
[4] => 1994
[5] => 1993
[6] => 1992
[7] => 1991
)
----
Server IP: 64.71.164.2
Probable Submitter: 66.142.223.81
----
Manual Page -- http://www.php.net/manual/en/function.strtotime.php
Edit -- https://master.php.net/note/edit/100975
Del: integrated -- https://master.php.net/note/delete/100975/integrated
Del: useless -- https://master.php.net/note/delete/100975/useless
Del: bad code -- https://master.php.net/note/delete/100975/bad+code
Del: spam -- https://master.php.net/note/delete/100975/spam
Del: non-english -- https://master.php.net/note/delete/100975/non-english
Del: in docs -- https://master.php.net/note/delete/100975/in+docs
Del: other reasons-- https://master.php.net/note/delete/100975
Reject -- https://master.php.net/note/reject/100975
Search -- https://master.php.net/manage/user-notes.php