RE: strange behaviour with strtotime()

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

 



On 31 January 2006 15:41, Barry wrote:

> Ford, Mike wrote:
> > Yes, but 1 apple is 1 apple is 1 apple.
> > 
> > 1 month can be 28 days, or 31 days, or anything in between.
> 2 months can be anything from 59 to 62 days.
> > 
> > A month is an imprecise measure, and adding them together
> will get you an even more imprecise result.
> > 
> > Deal with it -- that's just the way it is.
> > 
> > Cheers!
> 
> And now you tell me how the strtotime function tells what to use
> either 28 days or 31 days or 4 3/87 days.

It's very simple.  It uses the same day-of-the-month you start from: 1st gets you the 1st; 15th gets you the 15th; 31st gets you 31st or equivalent).  Put another way, "+1 month" adds as many days as there are days in the starting month; "+2 months" adds as many days as there are in the starting month and the one after (starting in Jan: 31+28 = 59 -- but starting in, say, Jul: 31+31 = 62); and so on.

Most of the time this gives you exactly what you want -- it's only when you ask starting from the 29th, 30th or 31st of a month, and the destination month is shorter, that it causes any kind of problem.  Since this is a very small, well-defined range of dates, it's fairly simple to deal with it -- once you know you need to!!

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: m.ford@xxxxxxxxxxxxxx
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 


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



[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