note 84145 modified in function.date by danbrown

From: Date: Sun, 20 Jul 2008 02:41:27 +0000
Subject: note 84145 modified in function.date by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141976@lists.php.net to get a copy of this message
Weeks and days for any month/year combo: <?php $m = 2; // February $Y = 2008; // constants used here for legibility, use $vars for dynamicon... define('MONTH_DAYS',date('t', strtotime(date($m . '/01/' . $Y)))); // w:0->6 = Sun->Sat define('MONTH_FIRST_DAY',date('w', strtotime(date($m . '/01/' . $Y)))); for($i = 1, $j = MONTH_FIRST_DAY, $w = 1;$i <= MONTH_DAYS;$i++) { $week[$w][$j] = $i; $j++; if($j == 7) { $j = 0; $w++; } } ?> print_r($week): ----------------------- Array ( [1] => Array ( [5] => 1 [6] => 2 ) [2] => Array ( [0] => 3 [1] => 4 [2] => 5 [3] => 6 [4] => 7 [5] => 8 [6] => 9 ) [3] => Array ( [0] => 10 [1] => 11 [2] => 12 [3] => 13 [4] => 14 [5] => 15 [6] => 16 ) [4] => Array ( [0] => 17 [1] => 18 [2] => 19 [3] => 20 [4] => 21 [5] => 22 [6] => 23 ) [5] => Array ( [0] => 24 [1] => 25 [2] => 26 [3] => 27 [4] => 28 [5] => 29 ) ) --was-- Weeks and days for any month/year combo: $m = 2; // February $Y = 2008; // constants used here for legibility, use $vars for dynamicon... define('MONTH_DAYS',date('t', strtotime(date($m . '/01/' . $Y)))); // w:0->6 = Sun->Sat define('MONTH_FIRST_DAY',date('w', strtotime(date($m . '/01/' . $Y)))); for($i = 1, $j = MONTH_FIRST_DAY, $w = 1;$i <= MONTH_DAYS;$i++) { $week[$w][$j] = $i; $j++; if($j == 7) { $j = 0; $w++; } } print_r($week): ----------------------- Array ( [1] => Array ( [5] => 1 [6] => 2 ) [2] => Array ( [0] => 3 [1] => 4 [2] => 5 [3] => 6 [4] => 7 [5] => 8 [6] => 9 ) [3] => Array ( [0] => 10 [1] => 11 [2] => 12 [3] => 13 [4] => 14 [5] => 15 [6] => 16 ) [4] => Array ( [0] => 17 [1] => 18 [2] => 19 [3] => 20 [4] => 21 [5] => 22 [6] => 23 ) [5] => Array ( [0] => 24 [1] => 25 [2] => 26 [3] => 27 [4] => 28 [5] => 29 ) ) http://php.net/manual/en/function.date.php

« previous php.notes (#141976) next »