Re: Function mktime() documentation question

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

 



On 10 March 2012 19:06, Matijn Woudt <tijnema@xxxxxxxxx> wrote:

> On Sat, Mar 10, 2012 at 6:20 PM, Maciek Sokolewicz
> <maciek.sokolewicz@xxxxxxxxx> 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 Brown<danbrown@xxxxxxx>  wrote:
> >>>
> >>> On Thu, Mar 8, 2012 at 21:23, Tedd Sperling<tedd.sperling@xxxxxxxxx>
> >>>  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

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

  Powered by Linux