note 51354 deleted from function.date by betz
| From: | betz@php.net | Date: | Thu, 31 Mar 2005 11:41:42 +0000 |
| Subject: | note 51354 deleted from function.date by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-87250@lists.php.net to get a copy of this message | ||
Note Submitter: redsolution at web dot de
----
Some experiments to find out first and last day of a week.
For sure not the best way, but a working one :)
<?php
$day = date ("j");
$month = date ("n");
$year = date ("Y");
(int)$dayofweek = date("w", mktime
(1,1,1,date("n"),date("j"),date("Y")));
$dayofweek = ($dayofweek == 0 ? 6 : $dayofweek-1);
(int)$thisweek = date("W", mktime(0,0,1,$month,$day,$year));
(int)$today = date("j", mktime(0,0,1,$month,$day,$year));
(int)$thismonthdays = date("t", mktime(0,0,1,$month,$day,$year));
(int)$lastmonthdays = date("t", mktime(0,0,1,$month-1,1,$year));
(int)$lastmonth = date("n", mktime(0,0,1,$month-1,1,$year));
(int)$nextmonth = date("n", mktime(23,59,59,$month+1,1,$year));
$firstweekday = ($dayofweek == 0 ? $today : ($today-$dayofweek<=0 ?
$lastmonthdays-($dayofweek-$today) : $today-$dayofweek));
$lastweekday = ($dayofweek == 6 ? $today : ($today+(6-$dayofweek) > $thismonthdays ?
(6-$dayofweek)-($thismonthdays-$today) : $today+(6-$dayofweek)));
$fwd_month = ($today-$dayofweek <= 0 ? $lastmonth : date("n"));
$fwd_year = ($fwd_month==$lastmonth && $fwd_month == 12 ? date("Y")-1 :
date("Y"));
$lwd_month = ($today+(6-$dayofweek) > $thismonthdays ? $nextmonth : date("n"));
$lwd_year = ($lwd_month==$nextmonth && $lwd_month == 1 ? date("Y")+1 :
date("Y"));
echo "Today: ".date("D d.M.Y");
echo "<br>".++$dayofweek.". day of $thisweek. week";
echo "<br>First day of week: ".date("D d.M.Y",
mktime(0,0,1,$fwd_month,$firstweekday,$fwd_year));
echo "<br>Last day of week: ".date("D d.M.Y",
mktime(23,59,59,$lwd_month,$lastweekday,$fwd_year));
?>