RE: Function mktime() documentation question

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

 



Tedd,
	This area was always a little grey to me. 
I have used -1 to obtain the previous months for some time now.
0 always indicated the beginning index of the current month but the
explanation never seemed to fit the bill.


Having worked extensively in time manipulation in many of the development
projects I have come up with a rule of thumb.


$this_month = date('Y-m-d 00:00:00',mktime(0,0,0,date('m'),1,date('Y')));
$previous_month = date('Y-m-d
00:00:00',mktime(0,0,0,date('m')-1,1,date('Y')));
$next_month = date('Y-m-d 00:00:00',mktime(0,0,0,date('m')+1,1,date('Y')));

To get the days of any given month or just about anything you need to just
use the strtotime
$days_in_month = date('j',strtotime($this_month));






-----Original Message-----
From: Tedd Sperling [mailto:tedd.sperling@xxxxxxxxx] 
Sent: Wednesday, March 07, 2012 3:04 PM
To: PHP-General List
Subject:  Function mktime() documentation question

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.

As such, I would re-write the relevant portion of the paragraph to be:

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 0 reference the days in the previous month.
For example, -1 is the day before the first day of the relevant month. The
value 0 is the zero index of the next month, which is also equal to the last
day of the relevant month. Values greater than zero are the number of days
in the relevant month reference the appropriate day in the following
month(s).

What say you?

Cheers,

tedd

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






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


-- 
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