note 69100 deleted from function.date by bobby

From: Date: Thu, 07 Sep 2006 18:17:23 +0000
Subject: note 69100 deleted from function.date by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-116861@lists.php.net to get a copy of this message
Note Submitter: Meijerink at NOSPAM dot gmail dot com ---- mwwaygoo AT hotmail DOT com 09-Aug-2006 05:11 Posted a nice script to calculate the number of weeks in a month using the ISO 8601 standard. But I was a little bit confused why to use the strtotime function. I tweaked it a little bit, using mtime to identify the first and last day of the month and making it all possible in 4 lines. <?php for ($j = 1; $j <= 10; $j++) { $year = date("Y")+ $j -5; echo("<br>".$year."<br>"); for ($i = 1; $i <= 12; $i++) { $month = $i; $first_week_no = date("W", mktime(1, 1, 1, $month, 1, $year)); $last_week_no = date("W", mktime(1, 1, 1, $month, date('t',mktime(0,0,0,$month,1,$year)), $year)); if($last_week_no < $first_week_no) { $weeks_of_month = 53 - $first_week_no + $last_week_no; } else { $weeks_of_month = $last_week_no - $first_week_no + 1;} echo(" Month:". $month); echo(" First Week".$first_week_no); echo(" Last week". $last_week_no); echo(" Total".$weeks_of_month ."<br>"); } } ?>

« previous php.notes (#116861) next »