note 38372 added to function.date
| From: | webmaster at daersys dot net | Date: | Thu, 18 Dec 2003 12:42:10 +0000 |
| Subject: | note 38372 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-62174@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38372
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38372&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38372&report=yes
Search -- http://master.php.net/manage/user-notes.php