php-general Digest 8 Mar 2012 10:19:15 -0000 Issue 7717
php-general Digest 8 Mar 2012 10:19:15 - Issue 7717 Topics (messages 316935 through 316938): Re: Function mktime() documentation question 316935 by: shiplu 316936 by: Simon Schick 316937 by: Charles eaccelerator and/or magickwand 316938 by: Lester Caine Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- 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 ---End Message--- ---BeginMessage--- 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 ---End Message--- ---BeginMessage--- 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'); ---End Message--- ---BeginMessage--- Anybody got eaccelerator and/or magickwand compiling for PHP5.4? I've got a nice new machine all set up, and would like to take it straight to Apache 2.4.1 and PHP5.4, but I'd also like to keep the same library setup as the 5.3 setup. -- 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 ---End Message---
php-general Digest 8 Mar 2012 23:12:45 -0000 Issue 7718
php-general Digest 8 Mar 2012 23:12:45 - Issue 7718 Topics (messages 316939 through 316939): Re: Function mktime() documentation question 316939 by: Tedd Sperling Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- 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 ---End Message---
[PHP] eaccelerator and/or magickwand
Anybody got eaccelerator and/or magickwand compiling for PHP5.4? I've got a nice new machine all set up, and would like to take it straight to Apache 2.4.1 and PHP5.4, but I'd also like to keep the same library setup as the 5.3 setup. -- 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
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
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
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
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
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
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
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
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
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