note 92337 added to function.getdate

From: Date: Mon, 20 Jul 2009 14:25:50 +0000
Subject: note 92337 added to function.getdate
Groups: php.notes 
Request: Send a blank email to php-notes+get-158507@lists.php.net to get a copy of this message
Modified version of cesar's function. Now it allows out-of-range values in $month, as in mktime() function, and returns FALSE instead of NULL if the arguments are invalid. <?php function getmonth ($month = null, $year = null) { // The current month is used if none is supplied. if (is_null($month)) $month = date('n'); // The current year is used if none is supplied. if (is_null($year)) $year = date('Y'); // Calculating the days of the month $first_of_month = mktime(0, 0, 0, $month, 1, $year); if ($first_of_month == -1 || $first_of_month === false) { return false; } $days_in_month = date('t', $first_of_month); $month = date('m', $first_of_month); $year = date('Y', $first_of_month); $last_of_month = mktime(0, 0, 0, $month, $days_in_month, $year); $m = array(); $m['first_mday'] = 1; $m['first_wday'] = date('w', $first_of_month); $m['first_weekday'] = strftime('%A', $first_of_month); $m['first_yday'] = date('z', $first_of_month); $m['first_week'] = date('W', $first_of_month); $m['last_mday'] = $days_in_month; $m['last_wday'] = date('w', $last_of_month); $m['last_weekday'] = strftime('%A', $last_of_month); $m['last_yday'] = date('z', $last_of_month); $m['last_week'] = date('W', $last_of_month); $m['mon'] = $month; $m['month'] = strftime('%B', $first_of_month); $m['year'] = $year; return $m; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 62.149.0.96 (proxied: 89.252.12.64) ---- Manual Page -- http://www.php.net/manual/en/function.getdate.php Edit -- https://master.php.net/note/edit/92337 Del: integrated -- https://master.php.net/note/delete/92337/integrated Del: useless -- https://master.php.net/note/delete/92337/useless Del: bad code -- https://master.php.net/note/delete/92337/bad+code Del: spam -- https://master.php.net/note/delete/92337/spam Del: non-english -- https://master.php.net/note/delete/92337/non-english Del: in docs -- https://master.php.net/note/delete/92337/in+docs Del: other reasons-- https://master.php.net/note/delete/92337 Reject -- https://master.php.net/note/reject/92337 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158507) next »