note 92337 deleted from function.getdate by danbrown

From: Date: Mon, 20 Jul 2009 15:08:16 +0000
Subject: note 92337 deleted from function.getdate by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-158510@lists.php.net to get a copy of this message
Note Submitter: ghost at acis org ua ---- 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; } ?>

« previous php.notes (#158510) next »