note 38372 deleted from function.date by kennyt
| From: | kennyt@php.net | Date: | Sun, 18 Jul 2004 17:29:24 +0000 |
| Subject: | note 38372 deleted from function.date by kennyt | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73516@lists.php.net to get a copy of this message | ||
Note Submitter: webmaster@daersys.net
----
I most recently had to write a function which will calculate all dates between a given start and
end-date (vacation-days management).
Just in case someone of you ought to do the same I thought I'd share the small piece of code.
Beware, the returned array will contain the actual start and end-dates as well.
Here goes:
<?php
function calculateVacationDays()
{
$date_from = '24.12.2003';
$date_to = '06.01.2004';
$date_from_parts = explode('.', $date_from);
$date_to_parts = explode('.', $date_to);
// Calculating the UNIX Timestamp for both dates
$ts_from = mktime(0, 0, 0, $date_from_parts[1], $date_from_parts[0], $date_from_parts[2]);
$ts_to = mktime(0, 0, 0, $date_to_parts[1], $date_to_parts[0], $date_to_parts[2]);
// 86400 = seconds per day
for ($x = $ts_from; $x <= $ts_to; $x += 86400)
{
$vacation_days[] = date('d.m.Y', $x);
}
return $vacation_days;
}
?>
If anyone knows a better/speedier/more elegant/whatever way to do this you're most welcome to
let me/us know :)
Take care
- Daerion