Re: Function mktime() documentation question
| From: | Daniel Brown | Date: | Wed, 07 Mar 2012 21:28:43 +0000 |
| Subject: | Re: Function mktime() documentation question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-316934@lists.php.net to get a copy of this message | ||
On Wed, Mar 7, 2012 at 15:03, Tedd Sperling <tedd.sperling@gmail.com> wrote:
> Hi gang:
>
> I am using the getdate(mktime()) functions to get month data (i.e., name of month, first
> weekday, last day, number of days).
>
> To get the number of days for a specific month, I use:
>
> // $current_month is the month under question
>
> $next_month = $current_month + 1;
> $what_date = getdate(mktime(0, 0, 0, $next_month, 0, $year));
> $days_in_current_month = $what_date['mday'];
>
> That works for me!
>
> However, if you read the documentation, namely:
>
> http://php.net/manual/en/function.mktime.php
>
> It states:
>
> --- quote
>
> day
>
> The number of the day relative to the end of the previous month. Values 1 to 28, 29, 30 or 31
> (depending upon the month) reference the normal days in the relevant month. Values less than 1
> (including negative values) reference the days in the previous month, so 0 is the last day of the
> previous month, -1 is the day before that, etc. Values greater than the number of days in the
> relevant month reference the appropriate day in the following month(s).
> --- un-quote
>
> From my code, the number of days in a month can be found by using 0 as the first index of the
> next month -- not the last day of the previous month.
I fail to follow. Your code is looking ahead to next month
(April), then using the 0 day, which means it's getting the last day
(31) of the current month (March). There's no such thing as a 0
April, hence anything less than one should count backward.
--
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/