note 28844 deleted from function.strtotime by sniper
| From: | sniper@php.net | Date: | Tue, 21 Oct 2003 11:02:38 +0000 |
| Subject: | note 28844 deleted from function.strtotime by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59009@lists.php.net to get a copy of this message | ||
Note Submitter: geoff@hoffmans.net
----
I needed a function to generate an array of mysql-formatted dates in-between two user-seleceded
dates.
Requires the use of both strtotime() and date().
Here's the function I wrote:
function dateRange($from, $to){
// $from and $to are mysql date strings like '2003-01-25', '2003-02-01'
$dates = array();
$fromDate = strtotime($from);
$toDate = strtotime($to);
$daysInclusive = ($toDate - $fromDate)/60/60/24;
// this is inclusive. If you need exclusive use 1 and <
for($daynum=0;$daynum<=$daysInclusive;$daynum++){
array_push($dates, date("Y-m-d", $fromDate+($daynum*60*60*24)));
}
return $dates;
}
Called like so:
$datearray = dateRange($_POST["start_date"], $_POST["end_date"]);
Hope it saves you a few minutes one day ;)