note 70633 added to function.getdate

From: Date: Sun, 22 Oct 2006 15:49:08 +0000
Subject: note 70633 added to function.getdate
Groups: php.notes 
Request: Send a blank email to php-notes+get-118976@lists.php.net to get a copy of this message
<?php /** * This function is similar to getdate() but it returns * the month information. * * Returns an associative array containing the month * information of the parameters, or the current month * if no parameters are given. * */ 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'); // Verifying if the month exist if (!checkdate($month, 1, $year)) return null; // Calculating the days of the month $first_of_month = mktime(0, 0, 0, $month, 1, $year); $days_in_month = date('t', $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; } // Output print_r(getmonth(11, 1978)); print_r(getmonth()); ?> ---- Server IP: 200.59.45.3 Probable Submitter: 201.250.80.219 ---- Manual Page -- http://www.php.net/manual/en/function.getdate.php Edit -- https://master.php.net/note/edit/70633 Del: integrated -- https://master.php.net/note/delete/70633/integrated Del: useless -- https://master.php.net/note/delete/70633/useless Del: bad code -- https://master.php.net/note/delete/70633/bad+code Del: spam -- https://master.php.net/note/delete/70633/spam Del: non-english -- https://master.php.net/note/delete/70633/non-english Del: in docs -- https://master.php.net/note/delete/70633/in+docs Del: other reasons-- https://master.php.net/note/delete/70633 Reject -- https://master.php.net/note/reject/70633 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#118976) next »