php-general Digest 8 Mar 2012 10:19:15 -0000 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


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

Reply via email to