note 59766 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 11 Jun 2006 11:41:48 +0000 |
| Subject: | note 59766 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114244@lists.php.net to get a copy of this message | ||
Note Submitter: ihr at rafft-es-einfach dot net
----
A function to return an array ($week) containing the first second of the the week
(["begin"]) and the last second of the week (["end"]).
NOTE:
1. I haven't tested it on ALL dates yet, but it should act sane anyay.
2. THIS SCRIPT IS NOT COPYRIGHTED IN ANY FORM.
<?php
$current_week=get_week_boundaries($time());
$the_next_sunday=$current_week["end"];
$the_last_monday=$current_week["begin"];
$now=$current_week["pov"];
function get_week_boundaries($int_time) {
//first: find monday 0:00
$weekdayid=date("w",$int_time);
$dayid=date("j",$int_time);
$monthid=date("n", $int_time);
$yearid=date("Y", $int_time);
$beginofday=mktime(0,0,0,$monthid,$dayid,$yearid);
$beginofweek=$beginofday - (($weekdayid-1) * 86400); //86400 == seconds of one day (24 hours)
//now add the value of one week and call it the end of the week
//NOTE: End of week is Sunday, 23:59:59. I think you could also use Monday 00:00:00 but I though
that'd suck
$endofweek=($beginofweek + 7 * 86400)-1;
$week["begin"]=$beginofweek;
$week["end"]=$endofweek;
$week["pov"]=$int_time;
return $week;
}
?>