Re: Function mktime() documentation question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03/08/2012 04:24 PM, Jim Lucas wrote:
On 03/08/2012 03:14 PM, Tedd Sperling wrote:
On Mar 8, 2012, at 11:20 AM, Ford, Mike wrote:
-----Original Message-----
From: Tedd Sperling [mailto:tedd.sperling@xxxxxxxxx]
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.

Huh? The 0th day of next month *is* the last day of the current month,
which gives you the number of days in the current month. QED.
I think it's possible you may be being confuzled by the number of
nexts and previouses floating around. Your mktime call is asking for
the 0th day of next month, i.e. the last day of the previous month of
next month, i.e. the last day of the current month. Which is exactly
what you say works. I think. :)

However, I agree that the description is not very well worded - saying
that days in the requested month are relative to the previous month is
very odd indeed if you ask me -- if they must be relative to anything,
why not the beginning of the relevant month? Actually, with a bit more
thought, I think I'd rewrite it something like this:

The day number relative to the given month. Day numbers 1 to 28, 29,
30 or 31 (depending on the month) refer to the normal days in the
month. Numbers less than 1 refer to days in the previous month, so 0
is the last day of the preceding month, -1 the day before that, etc.
Numbers greater than the actual number of days in the month refer to
days in the following month(s).


Mike:

Very well put.

You say:

Huh? The 0th day of next month *is* the last day of the current month,
which gives you the number of days in the current month.

That IS exactly what I am saying.

But why does anyone have to use the next month to figure out how many
days there are are in this month? Do you see my point?

It would have been better if one could use:

$what_date = getdate(mktime(0, 0, 0, $this_month, 0, $year));
$days_in_this_month = $what_date['nday']; // note an additional key
for getdate()

But instead, we have to use:

$next_month = $this_month +1;
$what_date = getdate(mktime(0, 0, 0, $next_month, 0, $year));
$days_in_this_month = $what_date['mday'];

Additionally, there's a perception problem. You say that 0 of the next
month *is* the last day of the current month -- as such, apparently
months overlap in your (and Dan's) explanation. Well... I agree with
both of you, but my objection is having to increase the month value by
one to get the number of days in the current month.

That's all I was saying.

Side-point: I find it interesting that getdate() has all sorts of neat
descriptions for the current month (such as, what weekday a numbered
day is), but lacks how many days are in the month. Doesn't that seem odd?

Cheers,

tedd

_____________________
tedd.sperling@xxxxxxxxx
http://sperling.com

I am surprised that nobody has come up with this one yet.

$what_date = getdate(mktime(0, 0, 0, $this_month, 35, $year));
$days_in_this_month = 35 - $what_date['mday'];

Even a one liner...

$what_date = getdate(mktime(0,0,0,$this_month,35,$year)-(35 * 86400));


--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
http://www.bendsource.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux