Re: [PHP] Function mktime() documentation question

2012-03-12 Thread Tedd Sperling
On Mar 11, 2012, at 3:10 PM, Matijn Woudt wrote:
 On Sun, Mar 11, 2012 at 7:33 PM, Tedd Sperling tedd.sperl...@gmail.com 
 wrote:
 Actually, this works for me:
 
 $days_in_month = date('t', mktime(0, 0, 0, $next_month, 0, $year));
 
 But again, I don't see why I have to use next month to find the number of 
 days in this month.
 
 That's because you're requesting day 0 of some month, which refers to
 the last day in the previous month.
 Try: $days_in_month = date('t', mktime(0, 0, 0, $next_month, 1, $year));
 
 - Matijn

I got that.

Beating the same dead horse again, I think day 0 of this month should contain 
the days in this month, but I am in the minority on this.

Cheers,

tedd

_
tedd.sperl...@gmail.com
http://sperling.com

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



Re: [PHP] Function mktime() documentation question

2012-03-12 Thread Ashley Sheridan
On Mon, 2012-03-12 at 15:53 -0400, Tedd Sperling wrote:

 On Mar 11, 2012, at 3:10 PM, Matijn Woudt wrote:
  On Sun, Mar 11, 2012 at 7:33 PM, Tedd Sperling tedd.sperl...@gmail.com 
  wrote:
  Actually, this works for me:
  
  $days_in_month = date('t', mktime(0, 0, 0, $next_month, 0, $year));
  
  But again, I don't see why I have to use next month to find the number 
  of days in this month.
  
  That's because you're requesting day 0 of some month, which refers to
  the last day in the previous month.
  Try: $days_in_month = date('t', mktime(0, 0, 0, $next_month, 1, $year));
  
  - Matijn
 
 I got that.
 
 Beating the same dead horse again, I think day 0 of this month should contain 
 the days in this month, but I am in the minority on this.
 
 Cheers,
 
 tedd
 
 _
 tedd.sperl...@gmail.com
 http://sperling.com
 


I think a lot of the confusion is that we're so used to array indexes
beginning at 0 that we tend to assume other things should start there
too. I found this confusing when I first came across the date stuff in
PHP. Now I'm used to it, it makes sense.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Function mktime() documentation question

2012-03-11 Thread Ashley Sheridan
On Sat, 2012-03-10 at 20:38 -0500, Tedd Sperling wrote:

 On Mar 10, 2012, at 12:20 PM, Maciek Sokolewicz wrote:
 
  function getAmountOfDaysInAMonth($month, $year) {
$days = array(31, (($year%4==0 and ($year%100  0 or $year%400==0)) ? 29 
  : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
return $days[$month+1];
  }
 
 I like that -- here's a small variation.
 
 function numberDaysMonth($month, $year)
   {
   // Leap year is definded as a year that is evenly divisible by four
   // AND (year NOT evenly divisible by 100 OR year IS evenly divisible by 
 400) 
   
   $feb = ($year%4 == 0  ($year%100 != 0 || $year%400 == 0) ) ? 29 : 28;
   $days = array(0, 31, $feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
   return $days[$month];
   }
 
 Cheers,
 
 tedd
 
 _
 tedd.sperl...@gmail.com
 http://sperling.com
 
 
 
 
 
 


I still don't see what's wrong with

date(t);

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Function mktime() documentation question

2012-03-11 Thread Tedd Sperling
On Mar 11, 2012, at 6:12 AM, Ashley Sheridan wrote:
 
 I still don't see what's wrong with
 
 date(t);
 
 -- 
 Thanks,
 Ash

Ash:

It's just too damn simple -- we need to make things complicated. :-)

Actually, this works for me:

$days_in_month = date('t', mktime(0, 0, 0, $next_month, 0, $year));

But again, I don't see why I have to use next month to find the number of 
days in this month.

O', the mysteries of life.

Cheers,

tedd

_
tedd.sperl...@gmail.com
http://sperling.com






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



Re: [PHP] Function mktime() documentation question

2012-03-11 Thread Matijn Woudt
On Sun, Mar 11, 2012 at 7:33 PM, Tedd Sperling tedd.sperl...@gmail.com wrote:
 On Mar 11, 2012, at 6:12 AM, Ashley Sheridan wrote:

 I still don't see what's wrong with

 date(t);

 --
 Thanks,
 Ash

 Ash:

 It's just too damn simple -- we need to make things complicated. :-)

 Actually, this works for me:

 $days_in_month = date('t', mktime(0, 0, 0, $next_month, 0, $year));

 But again, I don't see why I have to use next month to find the number of 
 days in this month.

That's because you're requesting day 0 of some month, which refers to
the last day in the previous month.
Try: $days_in_month = date('t', mktime(0, 0, 0, $next_month, 1, $year));

- Matijn

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



Re: [PHP] Function mktime() documentation question

2012-03-10 Thread Maciek Sokolewicz

On 09-03-2012 14:11, Daniel Brown wrote:

 (To the list, as well.  First day with my new fingers, apparently)

On Fri, Mar 9, 2012 at 08:09, Daniel Browndanbr...@php.net  wrote:

On Thu, Mar 8, 2012 at 21:23, Tedd Sperlingtedd.sperl...@gmail.com  wrote:

This starts getting a bit off-topic from your original email, but
knowing that you're trying to use it for teaching your classes at the
college, it may be of some value to you.


All of this aside, though, you may instead want to use something along the 
lines of date('d',strtotime('last day of this month')); in tandem with your 
date formatting.


That's a good idea, but


date('d',strtotime('last day of this month'));


gives me the number of days in *this* month, but not the next, or previous, 
month.

I need the result to be whatever date was selected -- something like:

$number_days = date('d',strtotime('last day of April, 2014'));

But that doesn't work.


Sure it does, though you may have some issues when using
punctuation, unnecessary words, or using capital letters for anything
other than proper names.  What version of PHP are you using?  I get
the correct answers for all of the following phrases:

last day of April 2014
last day of this month
last day of next month
last day of last month
third Saturday March 2012

Or you can even be excruciatingly redundant:

echo date('d',strtotime('last day of this
month',strtotime('next month')));
echo date('d',strtotime('last day of this
month',strtotime('February 2018')));
echo date('d',strtotime('second Monday',strtotime('September 2012')));







I must admit I'm still at a loss why people would want a function to 
tell them the amount of days in a month. That amount is pretty much 
fixed (except for february, but that's also mathematically easy to fix). 
So a simple function like:

function getAmountOfDaysInAMonth($month, $year) {
   $days = array(31, (($year%4==0 and ($year%100  0 or $year%400==0)) 
? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

   return $days[$month+1];
}

Would work just fine. Unless of course you want to count the amount of 
days during the changing of calendars (ie during the change of the 
julian calendar to the gregorian), or in different calendars altogether.


Why (ab)use the datetime library for such a very simple thing? In the 
last case, I would indeed use DateTime, simply because it's not an easy 
answer.

- Tul

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



Re: [PHP] Function mktime() documentation question

2012-03-10 Thread Matijn Woudt
On Sat, Mar 10, 2012 at 6:20 PM, Maciek Sokolewicz
maciek.sokolew...@gmail.com wrote:
 On 09-03-2012 14:11, Daniel Brown wrote:

     (To the list, as well.  First day with my new fingers, apparently)

 On Fri, Mar 9, 2012 at 08:09, Daniel Browndanbr...@php.net  wrote:

 On Thu, Mar 8, 2012 at 21:23, Tedd Sperlingtedd.sperl...@gmail.com
  wrote:

    This starts getting a bit off-topic from your original email, but
 knowing that you're trying to use it for teaching your classes at the
 college, it may be of some value to you.

 All of this aside, though, you may instead want to use something along
 the lines of date('d',strtotime('last day of this month')); in tandem with
 your date formatting.


 That's a good idea, but

 date('d',strtotime('last day of this month'));


 gives me the number of days in *this* month, but not the next, or
 previous, month.

 I need the result to be whatever date was selected -- something like:

 $number_days = date('d',strtotime('last day of April, 2014'));

 But that doesn't work.


    Sure it does, though you may have some issues when using
 punctuation, unnecessary words, or using capital letters for anything
 other than proper names.  What version of PHP are you using?  I get
 the correct answers for all of the following phrases:

        last day of April 2014
        last day of this month
        last day of next month
        last day of last month
        third Saturday March 2012

    Or you can even be excruciatingly redundant:

        echo date('d',strtotime('last day of this
 month',strtotime('next month')));
        echo date('d',strtotime('last day of this
 month',strtotime('February 2018')));
        echo date('d',strtotime('second Monday',strtotime('September
 2012')));





 I must admit I'm still at a loss why people would want a function to tell
 them the amount of days in a month. That amount is pretty much fixed (except
 for february, but that's also mathematically easy to fix). So a simple
 function like:
 function getAmountOfDaysInAMonth($month, $year) {
   $days = array(31, (($year%4==0 and ($year%100  0 or $year%400==0)) ? 29 :
 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
   return $days[$month+1];
 }

Shouldn't this be $month-1?

- Matijn

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



Re: [PHP] Function mktime() documentation question

2012-03-10 Thread Maciek Sokolewicz
On 10 March 2012 19:06, Matijn Woudt tijn...@gmail.com wrote:

 On Sat, Mar 10, 2012 at 6:20 PM, Maciek Sokolewicz
 maciek.sokolew...@gmail.com wrote:
  On 09-03-2012 14:11, Daniel Brown wrote:
 
  (To the list, as well.  First day with my new fingers,
 apparently)
 
  On Fri, Mar 9, 2012 at 08:09, Daniel Browndanbr...@php.net  wrote:
 
  On Thu, Mar 8, 2012 at 21:23, Tedd Sperlingtedd.sperl...@gmail.com
   wrote:
 
 This starts getting a bit off-topic from your original email, but
  knowing that you're trying to use it for teaching your classes at the
  college, it may be of some value to you.
 
  All of this aside, though, you may instead want to use something
 along
  the lines of date('d',strtotime('last day of this month')); in
 tandem with
  your date formatting.
 
 
  That's a good idea, but
 
  date('d',strtotime('last day of this month'));
 
 
  gives me the number of days in *this* month, but not the next, or
  previous, month.
 
  I need the result to be whatever date was selected -- something like:
 
  $number_days = date('d',strtotime('last day of April, 2014'));
 
  But that doesn't work.
 
 
 Sure it does, though you may have some issues when using
  punctuation, unnecessary words, or using capital letters for anything
  other than proper names.  What version of PHP are you using?  I get
  the correct answers for all of the following phrases:
 
 last day of April 2014
 last day of this month
 last day of next month
 last day of last month
 third Saturday March 2012
 
 Or you can even be excruciatingly redundant:
 
 echo date('d',strtotime('last day of this
  month',strtotime('next month')));
 echo date('d',strtotime('last day of this
  month',strtotime('February 2018')));
 echo date('d',strtotime('second Monday',strtotime('September
  2012')));
 
 
 
 
 
  I must admit I'm still at a loss why people would want a function to tell
  them the amount of days in a month. That amount is pretty much fixed
 (except
  for february, but that's also mathematically easy to fix). So a simple
  function like:
  function getAmountOfDaysInAMonth($month, $year) {
$days = array(31, (($year%4==0 and ($year%100  0 or $year%400==0)) ?
 29 :
  28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
return $days[$month+1];
  }

 Shouldn't this be $month-1?

 - Matijn


Ehr, sorry, yes, you're right; well spotted! :)

- Tul


Re: [PHP] Function mktime() documentation question

2012-03-10 Thread tamouse mailing lists
I'm just a bit baffled why this isn't a standard library function.

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



Re: [PHP] Function mktime() documentation question

2012-03-10 Thread Matijn Woudt
On Sat, Mar 10, 2012 at 9:47 PM, tamouse mailing lists
tamouse.li...@gmail.com wrote:
 I'm just a bit baffled why this isn't a standard library function.

Good question, but I think the problem here is that there are tons of
these small functions, and you got to make a choice on what to
implement and what not. I can think of at least 20 other functions I'd
like to have integrated, but IMO PHP shouldn't be bloated with tons of
just 'useful' functions.

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



Re: [PHP] Function mktime() documentation question

2012-03-10 Thread Tedd Sperling
On Mar 10, 2012, at 12:20 PM, Maciek Sokolewicz wrote:

 function getAmountOfDaysInAMonth($month, $year) {
   $days = array(31, (($year%4==0 and ($year%100  0 or $year%400==0)) ? 29 : 
 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
   return $days[$month+1];
 }

I like that -- here's a small variation.

function numberDaysMonth($month, $year)
{
// Leap year is definded as a year that is evenly divisible by four
// AND (year NOT evenly divisible by 100 OR year IS evenly divisible by 
400) 

$feb = ($year%4 == 0  ($year%100 != 0 || $year%400 == 0) ) ? 29 : 28;
$days = array(0, 31, $feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
return $days[$month];
}

Cheers,

tedd

_
tedd.sperl...@gmail.com
http://sperling.com






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



RE: [PHP] Function mktime() documentation question

2012-03-09 Thread Ford, Mike
 -Original Message-
 From: Tedd Sperling [mailto:tedd.sperl...@gmail.com]
 Sent: 08 March 2012 23:15
 To: PHP-General List

[previous discussion snipped]
 
 
 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?

Actually, no. To figure this out, somewhere along the line you've
got to know where the last day of this month / first day of next
month boundary lies, so I don't see how you can ever find the number
of days in a month without bringing the start of next month into it
somehow. (Even if it's implicitly be getting someone else's clever
code to figure out 'last day of this month'!)
 
 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 that $what_date would still refer to a day in *last* month!
(Which isn't going to change, as it would be a significant BC break.)

 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'];

To me, that's a clever and elegant solution. It's clear that our
brains just work differently on this one.

 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.

Not overlap as such, I don't think -- there's just a continuum such
that the 0th of a month is the day before the 1st (and hence the last
day of the preceding month!), the -1th is the day before that and so
on; likewise, the 32nd is the day after the 31st, and so on.

 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?

Now that's a decent point: I can see where you're coming from with that
one. I don't know what performance penalty there might be (if any) to
calculate that for every call to getdate(), but it certainly seems like
a reasonable feature request.

(And, actually, I think we should be quite grateful that mktime()
*does* take out-of-range values and do appropriate things with them --
if it didn't, I suspect the only way to do this job might be a loop
similar to the one posted by Tedd, but adding chunks of 86400 to a raw
timestamp. Now that really would be a bit obscure!!!)

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730





To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

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



Re: [PHP] Function mktime() documentation question

2012-03-09 Thread Lester Caine

Ford, Mike wrote:

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?

Now that's a decent point: I can see where you're coming from with that
one. I don't know what performance penalty there might be (if any) to
calculate that for every call to getdate(), but it certainly seems like
a reasonable feature request.


I've never had this problem ;)
http://phplens.com/phpeverywhere/adodb_date_library

--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

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



Re: [PHP] Function mktime() documentation question

2012-03-09 Thread Daniel Brown
(To the list, as well.  First day with my new fingers, apparently)

On Fri, Mar 9, 2012 at 08:09, Daniel Brown danbr...@php.net wrote:
 On Thu, Mar 8, 2012 at 21:23, Tedd Sperling tedd.sperl...@gmail.com wrote:

    This starts getting a bit off-topic from your original email, but
 knowing that you're trying to use it for teaching your classes at the
 college, it may be of some value to you.

 All of this aside, though, you may instead want to use something along the 
 lines of date('d',strtotime('last day of this month')); in tandem with your 
 date formatting.

 That's a good idea, but

 date('d',strtotime('last day of this month'));

 gives me the number of days in *this* month, but not the next, or previous, 
 month.

 I need the result to be whatever date was selected -- something like:

 $number_days = date('d',strtotime('last day of April, 2014'));

 But that doesn't work.

    Sure it does, though you may have some issues when using
 punctuation, unnecessary words, or using capital letters for anything
 other than proper names.  What version of PHP are you using?  I get
 the correct answers for all of the following phrases:

        last day of April 2014
        last day of this month
        last day of next month
        last day of last month
        third Saturday March 2012

    Or you can even be excruciatingly redundant:

        echo date('d',strtotime('last day of this
 month',strtotime('next month')));
        echo date('d',strtotime('last day of this
 month',strtotime('February 2018')));
        echo date('d',strtotime('second Monday',strtotime('September 2012')));

 --
 /Daniel P. Brown
 Network Infrastructure Manager
 http://www.php.net/



-- 
/Daniel P. Brown
Network Infrastructure Manager
http://www.php.net/

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



Re: [PHP] Function mktime() documentation question

2012-03-09 Thread Tedd Sperling
On Mar 9, 2012, at 5:37 AM, Ford, Mike wrote:
 From: Tedd Sperling [mailto:tedd.sperl...@gmail.com]
 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?
 
 Actually, no. To figure this out, somewhere along the line you've
 got to know where the last day of this month / first day of next
 month boundary lies, so I don't see how you can ever find the number
 of days in a month without bringing the start of next month into it
 somehow. (Even if it's implicitly be getting someone else's clever
 code to figure out 'last day of this month'!)

Well no, I don't need to know the first day of next month to know the last day 
of this month. That's like saying I need to know who is going to stand at the 
'end of the line' NEXT before I can tell who is standing at the 'end of the' 
line NOW.

I like things to be self-contained. For the exception of multiverse arguments, 
everything should be self evident.

 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'];
 
 To me, that's a clever and elegant solution. It's clear that our
 brains just work differently on this one.

We all have differences in perception, how we analyze problems, and how we 
create solutions -- and that's a good thing.

 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?
 
 Now that's a decent point: I can see where you're coming from with that
 one. I don't know what performance penalty there might be (if any) to
 calculate that for every call to getdate(), but it certainly seems like
 a reasonable feature request.

I'm glad I have a decent point somewhere in this exchange and that we agree on 
something.  :-)

Cheers,

tedd


_
tedd.sperl...@gmail.com
http://sperling.com







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



Re: [PHP] Function mktime() documentation question

2012-03-09 Thread Charles
On Fri, Mar 9, 2012 at 10:58 PM, Tedd Sperling tedd.sperl...@gmail.com wrote:
 On Mar 9, 2012, at 5:37 AM, Ford, Mike wrote:
 From: Tedd Sperling [mailto:tedd.sperl...@gmail.com]
 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?

 Actually, no. To figure this out, somewhere along the line you've
 got to know where the last day of this month / first day of next
 month boundary lies, so I don't see how you can ever find the number
 of days in a month without bringing the start of next month into it
 somehow. (Even if it's implicitly be getting someone else's clever
 code to figure out 'last day of this month'!)

 Well no, I don't need to know the first day of next month to know the last 
 day of this month. That's like saying I need to know who is going to stand 
 at the 'end of the line' NEXT before I can tell who is standing at the 'end 
 of the' line NOW.

The number of days in each month is fixed, except for february. If
that's what you want, why don't make a table of the number of days in
each month, and check for the special case of leap year.

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



Re: [PHP] Function mktime() documentation question

2012-03-09 Thread Tedd Sperling
On Mar 9, 2012, at 11:17 AM, Charles wrote:

 On Fri, Mar 9, 2012 at 10:58 PM, Tedd Sperling tedd.sperl...@gmail.com 
 wrote:
 On Mar 9, 2012, at 5:37 AM, Ford, Mike wrote:
 From: Tedd Sperling [mailto:tedd.sperl...@gmail.com]
 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?
 
 Actually, no. To figure this out, somewhere along the line you've
 got to know where the last day of this month / first day of next
 month boundary lies, so I don't see how you can ever find the number
 of days in a month without bringing the start of next month into it
 somehow. (Even if it's implicitly be getting someone else's clever
 code to figure out 'last day of this month'!)
 
 Well no, I don't need to know the first day of next month to know the last 
 day of this month. That's like saying I need to know who is going to stand 
 at the 'end of the line' NEXT before I can tell who is standing at the 'end 
 of the' line NOW.
 
 The number of days in each month is fixed, except for february. If
 that's what you want, why don't make a table of the number of days in
 each month, and check for the special case of leap year.

No offense, but that's not the point. A look-up table would work, but why when 
there are all sorts of built-in functions that will?

I am just looking for one that is easy to explain to students. 

Cheers,

tedd


_
tedd.sperl...@gmail.com
http://sperling.com


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



Re: [PHP] Function mktime() documentation question

2012-03-09 Thread Charles
On Sat, Mar 10, 2012 at 12:07 AM, Tedd Sperling tedd.sperl...@gmail.com wrote:
 On Mar 9, 2012, at 11:17 AM, Charles wrote:

 On Fri, Mar 9, 2012 at 10:58 PM, Tedd Sperling tedd.sperl...@gmail.com 
 wrote:
 On Mar 9, 2012, at 5:37 AM, Ford, Mike wrote:
 From: Tedd Sperling [mailto:tedd.sperl...@gmail.com]
 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?

 Actually, no. To figure this out, somewhere along the line you've
 got to know where the last day of this month / first day of next
 month boundary lies, so I don't see how you can ever find the number
 of days in a month without bringing the start of next month into it
 somehow. (Even if it's implicitly be getting someone else's clever
 code to figure out 'last day of this month'!)

 Well no, I don't need to know the first day of next month to know the last 
 day of this month. That's like saying I need to know who is going to stand 
 at the 'end of the line' NEXT before I can tell who is standing at the 'end 
 of the' line NOW.

 The number of days in each month is fixed, except for february. If
 that's what you want, why don't make a table of the number of days in
 each month, and check for the special case of leap year.

 No offense, but that's not the point. A look-up table would work, but why 
 when there are all sorts of built-in functions that will?

You just said yourself that I don't need to know the first day of
next month to know the last day of this month, and AFAIK there is no
such function in PHP to get the number of days
without accessing the last second in the month. Besides, showing how
it is done is part of education.

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



Fwd: [PHP] Function mktime() documentation question

2012-03-09 Thread Andrew Ballard
And again to the list, since for some reason Reply-to-all did not do
as intended this time.


-- Forwarded message --
From: Andrew Ballard aball...@gmail.com
Date: Fri, Mar 9, 2012 at 12:53 PM
Subject: Re: [PHP] Function mktime() documentation question
To: Tedd Sperling tedd.sperl...@gmail.com


On Fri, Mar 9, 2012 at 12:07 PM, Tedd Sperling tedd.sperl...@gmail.com wrote:

[snip]

 I am just looking for one that is easy to explain to students.

 Cheers,

 tedd

tedd,

Since you are teaching this to students, I would recommend sticking
with the internal date functions and avoiding any solution that
includes adding or subtracting multiples of the magic number 86400.*
Many such solutions fail to take into consideration Daylight Saving
Time and are therefore guaranteed to be wrong at least twice a year
(if not several months out of the year). Sure, you can write your code
to handle the differences correctly, but since the rules governing the
time shift are mostly arbitrary and differ across time zones the world
over, it seems safer to me to rely on the internal functions when
working with dates.


Andrew


* Even if the internal functions base their calculations on the number
of seconds per day, they have at least already handled all the varied
time zones and DST rules and been tested in environments all over the
world. When those rules change, the internal functions will be
adjusted to reflect the changes and should be much more reliable than
thousands of instances of multiple strategies that get copied and
pasted into projects.

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



Re: [PHP] Function mktime() documentation question

2012-03-09 Thread Charles
On Sat, Mar 10, 2012 at 12:52 AM, Charles peac...@gmail.com wrote:
 On Sat, Mar 10, 2012 at 12:07 AM, Tedd Sperling tedd.sperl...@gmail.com 
 wrote:
 On Mar 9, 2012, at 11:17 AM, Charles wrote:

 On Fri, Mar 9, 2012 at 10:58 PM, Tedd Sperling tedd.sperl...@gmail.com 
 wrote:
 On Mar 9, 2012, at 5:37 AM, Ford, Mike wrote:
 From: Tedd Sperling [mailto:tedd.sperl...@gmail.com]
 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?

 Actually, no. To figure this out, somewhere along the line you've
 got to know where the last day of this month / first day of next
 month boundary lies, so I don't see how you can ever find the number
 of days in a month without bringing the start of next month into it
 somehow. (Even if it's implicitly be getting someone else's clever
 code to figure out 'last day of this month'!)

 Well no, I don't need to know the first day of next month to know the last 
 day of this month. That's like saying I need to know who is going to 
 stand at the 'end of the line' NEXT before I can tell who is standing at 
 the 'end of the' line NOW.

 The number of days in each month is fixed, except for february. If
 that's what you want, why don't make a table of the number of days in
 each month, and check for the special case of leap year.

 No offense, but that's not the point. A look-up table would work, but why 
 when there are all sorts of built-in functions that will?

 You just said yourself that I don't need to know the first day of
 next month to know the last day of this month, and AFAIK there is no
 such function in PHP to get the number of days
 without accessing the last second in the month. Besides, showing how
 it is done is part of education.

Unless, of course you install the calendar extension, of which it
will provides just the required function

http://php.net/manual/en/function.cal-days-in-month.php

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



Re: [PHP] Function mktime() documentation question

2012-03-09 Thread Ashley Sheridan


Charles peac...@gmail.com wrote:

On Sat, Mar 10, 2012 at 12:52 AM, Charles peac...@gmail.com wrote:
 On Sat, Mar 10, 2012 at 12:07 AM, Tedd Sperling
tedd.sperl...@gmail.com wrote:
 On Mar 9, 2012, at 11:17 AM, Charles wrote:

 On Fri, Mar 9, 2012 at 10:58 PM, Tedd Sperling
tedd.sperl...@gmail.com wrote:
 On Mar 9, 2012, at 5:37 AM, Ford, Mike wrote:
 From: Tedd Sperling [mailto:tedd.sperl...@gmail.com]
 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?

 Actually, no. To figure this out, somewhere along the line you've
 got to know where the last day of this month / first day of next
 month boundary lies, so I don't see how you can ever find the
number
 of days in a month without bringing the start of next month into
it
 somehow. (Even if it's implicitly be getting someone else's
clever
 code to figure out 'last day of this month'!)

 Well no, I don't need to know the first day of next month to know
the last day of this month. That's like saying I need to know who is
going to stand at the 'end of the line' NEXT before I can tell who is
standing at the 'end of the' line NOW.

 The number of days in each month is fixed, except for february. If
 that's what you want, why don't make a table of the number of days
in
 each month, and check for the special case of leap year.

 No offense, but that's not the point. A look-up table would work,
but why when there are all sorts of built-in functions that will?

 You just said yourself that I don't need to know the first day of
 next month to know the last day of this month, and AFAIK there is no
 such function in PHP to get the number of days
 without accessing the last second in the month. Besides, showing how
 it is done is part of education.

Unless, of course you install the calendar extension, of which it
will provides just the required function

http://php.net/manual/en/function.cal-days-in-month.php

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

What about just doing this:

intval(date(t));

And you can pass in an argument to date() if you need a specific month.

Thanks,
Ash
http://ashleysheridan.co.uk

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



Re: [PHP] Function mktime() documentation question

2012-03-09 Thread Charles
On Sat, Mar 10, 2012 at 12:57 AM, Charles peac...@gmail.com wrote:
 On Sat, Mar 10, 2012 at 12:52 AM, Charles peac...@gmail.com wrote:
 On Sat, Mar 10, 2012 at 12:07 AM, Tedd Sperling tedd.sperl...@gmail.com 
 wrote:
 On Mar 9, 2012, at 11:17 AM, Charles wrote:

 On Fri, Mar 9, 2012 at 10:58 PM, Tedd Sperling tedd.sperl...@gmail.com 
 wrote:
 On Mar 9, 2012, at 5:37 AM, Ford, Mike wrote:
 From: Tedd Sperling [mailto:tedd.sperl...@gmail.com]
 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?

 Actually, no. To figure this out, somewhere along the line you've
 got to know where the last day of this month / first day of next
 month boundary lies, so I don't see how you can ever find the number
 of days in a month without bringing the start of next month into it
 somehow. (Even if it's implicitly be getting someone else's clever
 code to figure out 'last day of this month'!)

 Well no, I don't need to know the first day of next month to know the 
 last day of this month. That's like saying I need to know who is going 
 to stand at the 'end of the line' NEXT before I can tell who is standing 
 at the 'end of the' line NOW.

 The number of days in each month is fixed, except for february. If
 that's what you want, why don't make a table of the number of days in
 each month, and check for the special case of leap year.

 No offense, but that's not the point. A look-up table would work, but why 
 when there are all sorts of built-in functions that will?

 You just said yourself that I don't need to know the first day of
 next month to know the last day of this month, and AFAIK there is no
 such function in PHP to get the number of days
 without accessing the last second in the month. Besides, showing how
 it is done is part of education.

 Unless, of course you install the calendar extension, of which it
 will provides just the required function

 http://php.net/manual/en/function.cal-days-in-month.php

Okay, scratch that, the standard function works fine

$number_of_days = idate('t', strtotime($year.'-'.$month));

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



Re: [PHP] Function mktime() documentation question

2012-03-09 Thread Tedd Sperling
On Mar 9, 2012, at 12:52 PM, Charles wrote:
 On Sat, Mar 10, 2012 at 12:07 AM, Tedd Sperling tedd.sperl...@gmail.com 
 wrote:
 
 Well no, I don't need to know the first day of next month to know the last 
 day of this month. That's like saying I need to know who is going to stand 
 at the 'end of the line' NEXT before I can tell who is standing at the 'end 
 of the' line NOW.
 
 You just said yourself that I don't need to know the first day of
 next month to know the last day of this month, and AFAIK there is no
 such function in PHP to get the number of days
 without accessing the last second in the month. Besides, showing how
 it is done is part of education.

Arrggg.

When I said I, I meant I and not a php function.

Sometimes the point is never made.

tedd

_
tedd.sperl...@gmail.com
http://sperling.com



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



Re: [PHP] Function mktime() documentation question

2012-03-08 Thread Tedd Sperling
On Mar 7, 2012, at 4:28 PM, Daniel Brown wrote:

 On Wed, Mar 7, 2012 at 15:03, Tedd Sperling tedd.sperl...@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

Daniel:

Yes, it uses next month to figure out this month -- that's my point.

See my reply to Mike Ford.

Cheers,

tedd

_
tedd.sperl...@gmail.com
http://sperling.com




















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



Re: [PHP] Function mktime() documentation question

2012-03-08 Thread Tedd Sperling
On Mar 8, 2012, at 11:20 AM, Ford, Mike wrote:
 -Original Message-
 From: Tedd Sperling [mailto:tedd.sperl...@gmail.com]
 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.sperl...@gmail.com
http://sperling.com











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



Re: [PHP] Function mktime() documentation question

2012-03-08 Thread Daniel Brown
On Mar 8, 2012 6:14 PM, Tedd Sperling tedd.sperl...@gmail.com wrote:

 On Mar 8, 2012, at 11:20 AM, Ford, Mike wrote:
  -Original Message-
  From: Tedd Sperling [mailto:tedd.sperl...@gmail.com]
  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?

Oh, I see what you're saying now.  Well, using getdate(), how else would
you think to pass the parameter to get the last day other than using the
current month and the last day (which would then obviously be overkill, of
course).

All of this aside, though, you may instead want to use something along the
lines of date('d',strtotime('last day of this month')); in tandem with your
date formatting.


Re: [PHP] Function mktime() documentation question

2012-03-08 Thread Jim Lucas

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.sperl...@gmail.com]
 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.sperl...@gmail.com
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'];



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



Re: [PHP] Function mktime() documentation question

2012-03-08 Thread Jim Lucas

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.sperl...@gmail.com]
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.sperl...@gmail.com
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



Re: [PHP] Function mktime() documentation question

2012-03-08 Thread Jim Lucas

On 03/08/2012 04:31 PM, Jim Lucas wrote:

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.sperl...@gmail.com]
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.sperl...@gmail.com
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));




Sorry, had my math backwards...

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

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



Re: [PHP] Function mktime() documentation question

2012-03-08 Thread Jim Lucas

On 03/08/2012 04:44 PM, Jim Lucas wrote:

On 03/08/2012 04:31 PM, Jim Lucas wrote:

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.sperl...@gmail.com]
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.sperl...@gmail.com
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));




Sorry, had my math backwards...

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



Spoke too soon.  Since you have to know the output of getdate() to 
calculate the minus figure... I guess that won't work.  Use the first 
one that I suggested.


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



Re: [PHP] Function mktime() documentation question

2012-03-08 Thread Tedd Sperling
On Mar 8, 2012, at 6:53 PM, Daniel Brown wrote:
On Mar 8, 2012 6:14 PM, Tedd Sperling tedd.sperl...@gmail.com wrote:
 
  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?
 
 Oh, I see what you're saying now.  Well, using getdate(), how else would you 
 think to pass the parameter to get the last day other than using the current 
 month and the last day (which would then obviously be overkill, of course).

Well.. you could use any number that exceeds 31 -- or -- as I would have 
suggested if it had been up to me, zero day would provide the number of days in 
*that* month rather than the number of days in the previous month, which was 
the point of my post.

 All of this aside, though, you may instead want to use something along the 
 lines of date('d',strtotime('last day of this month')); in tandem with your 
 date formatting.

That's a good idea, but 

 date('d',strtotime('last day of this month'));


gives me the number of days in *this* month, but not the next, or previous, 
month.

I need the result to be whatever date was selected -- something like:

$number_days = date('d',strtotime('last day of April, 2014'));

But that doesn't work.

You see, I need something that makes sense to students. The idea that you have 
to use the zero day (whatever that is) of the next month to see how many days 
there are in this month is strange and confusing -- again my point.

Thus far, the following looks better than what I came up with::

$what_date = getdate(mktime(0, 0, 0, $mon, 32, $year));
$days_in_month = 32 - $what_date['mday'];

But it's still strange.

I was using:

// get the last day of the month
$cont = true;
$tday = 27;
while (($tday = 32)  ($cont))
{
$tdate = getdate(mktime(0,0,0,$mon,$tday,$year));
if ($tdate[mon] != $mon)
{
$lastday = $tday - 1;
$cont = false;
}
$tday++;
}

It made sense, but was too long. I figured there should be something better and 
easier to explain -- but I'm still looking.

Cheers


tedd

_
tedd.sperl...@gmail.com
http://sperling.com






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



Re: [PHP] Function mktime() documentation question

2012-03-08 Thread Charles
On Fri, Mar 9, 2012 at 9:23 AM, Tedd Sperling tedd.sperl...@gmail.com wrote:
 On Mar 8, 2012, at 6:53 PM, Daniel Brown wrote:
 On Mar 8, 2012 6:14 PM, Tedd Sperling tedd.sperl...@gmail.com wrote:

  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?

 Oh, I see what you're saying now.  Well, using getdate(), how else would you 
 think to pass the parameter to get the last day other than using the current 
 month and the last day (which would then obviously be overkill, of course).

 Well.. you could use any number that exceeds 31 -- or -- as I would have 
 suggested if it had been up to me, zero day would provide the number of days 
 in *that* month rather than the number of days in the previous month, which 
 was the point of my post.

 All of this aside, though, you may instead want to use something along the 
 lines of date('d',strtotime('last day of this month')); in tandem with your 
 date formatting.

 That's a good idea, but

 date('d',strtotime('last day of this month'));


 gives me the number of days in *this* month, but not the next, or previous, 
 month.

 I need the result to be whatever date was selected -- something like:

 $number_days = date('d',strtotime('last day of April, 2014'));

 But that doesn't work.

 You see, I need something that makes sense to students. The idea that you 
 have to use the zero day (whatever that is) of the next month to see how many 
 days there are in this month is strange and confusing -- again my point.

 Thus far, the following looks better than what I came up with::

 $what_date = getdate(mktime(0, 0, 0, $mon, 32, $year));
 $days_in_month = 32 - $what_date['mday'];

 But it's still strange.

 I was using:

        // get the last day of the month
        $cont = true;
        $tday = 27;
        while (($tday = 32)  ($cont))
                {
                $tdate = getdate(mktime(0,0,0,$mon,$tday,$year));
                if ($tdate[mon] != $mon)
                        {
                        $lastday = $tday - 1;
                        $cont = false;
                        }
                $tday++;
                }

 It made sense, but was too long. I figured there should be something better 
 and easier to explain -- but I'm still looking.

function count_days($month, $year) { return (mktime(0, 0, 0, $month+1,
1, $year) - mktime(0, 0, 0, $month, 1, $year))/86400; }

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



[PHP] Function mktime() documentation question

2012-03-07 Thread Tedd Sperling
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.sperl...@gmail.com
http://sperling.com






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



RE: [PHP] Function mktime() documentation question

2012-03-07 Thread admin
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.sperl...@gmail.com] 
Sent: Wednesday, March 07, 2012 3:04 PM
To: PHP-General List
Subject: [PHP] 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.sperl...@gmail.com
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



Re: [PHP] Function mktime() documentation question

2012-03-07 Thread Daniel Brown
On Wed, Mar 7, 2012 at 15:03, Tedd Sperling tedd.sperl...@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/

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



Re: [PHP] Function mktime() documentation question

2012-03-07 Thread shiplu
 To get the number of days for a specific month, I use:

 // $current_month is the month under question

 $next_month = $current_month + 1;

I use this

$next_month = $current_month + 1;
$next_month_1= mktime(0, 0, 0, $next_month, 1, date(Y) );
$current_month_1= mktime(0, 0, 0, $current_month, 1, date(Y) );
$mdays = ($current_month_1 - $next_month_1)/(3600*24);

It's much more easier if you use DateTime and DateInterval class



-- 
Shiplu.Mokadd.im
ImgSign.com | A dynamic signature machine
Innovation distinguishes between follower and leader


Re: [PHP] Function mktime() documentation question

2012-03-07 Thread Simon Schick
Hi, All

To bring a work-around into this discussion I myself would not see it
as a good way to do it like that - even if the documentation provides
some information around that.
Here's what I have done in all new projects I worked with time-calculation:

@Tedd: Lets pick up your first example and work with the
DateTime-Object instead:

$date = new DateTime($year . '-' . $current_month . '-1');
$date-add( new DateInterval( 'P1M' ) ); // Add a period of 1 month to
the date-instance (haven't tried that with the 30th of Jan ... would
be kind-of interesting)

$days_in_current_month = $date-format('j'); // Get the date of the month

As this does not solve the problem (as we still should update the
documentation or the code if it does not match) it's not a solution,
but a suggestion to coding-style at all.
It seems a bit cleaner to me as you don't have to worry about the 13th
month, time-zones or other things that can be difficult to calculate
yourself.

Bye
Simon

2012/3/8 shiplu shiplu@gmail.com:
 To get the number of days for a specific month, I use:

 // $current_month is the month under question

 $next_month = $current_month + 1;

 I use this

 $next_month = $current_month + 1;
 $next_month_1    = mktime(0, 0, 0,     $next_month, 1, date(Y) );
 $current_month_1= mktime(0, 0, 0, $current_month, 1, date(Y) );
 $mdays = ($current_month_1 - $next_month_1)/(3600*24);

 It's much more easier if you use DateTime and DateInterval class



 --
 Shiplu.Mokadd.im
 ImgSign.com | A dynamic signature machine
 Innovation distinguishes between follower and leader

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



Re: [PHP] Function mktime() documentation question

2012-03-07 Thread Charles
On Thu, Mar 8, 2012 at 7:01 AM, Simon Schick
simonsimc...@googlemail.com wrote:
 $date = new DateTime($year . '-' . $current_month . '-1');
 $date-add( new DateInterval( 'P1M' ) ); // Add a period of 1 month to
 the date-instance (haven't tried that with the 30th of Jan ... would
 be kind-of interesting)

 $days_in_current_month = $date-format('j'); // Get the date of the month

I think you'd need to subtract it with 1 day

date_create(date('Y-m'))-add(new DateInterval('P1M'))-sub(new
DateInterval('P1D'))-format('d');

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