note 80846 deleted from function.mktime by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 03:31:03 +0000 |
| Subject: | note 80846 deleted from function.mktime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142068@lists.php.net to get a copy of this message | ||
Note Submitter: Nate from nooberouno dot com
----
// How to get the UNIX Time for Sunday of any week of the year. I need it for consistant weekly
features regardless of the year.
// Current Week Number
$weeknumber = date("W");
// UNIX Time for Jan 1, (current year)
$firstweek = mktime(0,0,0,1,1,date("Y"));
// UNIX Time for the start of the current week (Usually not a Sunday)
$currentweek = $firstweek+($weeknumber*604800)-604800;
// Checks what day of the week it is, then adds a day until its Sunday
$sundaycheck = date("w",$currentweek);
do{
if($sundaycheck!=0){
$currentweek += 86400;
$sundaycheck = date("w",$currentweek);
}
}while($sundaycheck!=0);
echo date("l jS F, Y @ H:i:s a", $currentweek)."<br>";
// Will display the Sunday of the current week.