Re: Maintainer of Date_Calc
| From: | Tomas V.V.Cox | Date: | Tue, 07 Aug 2001 14:19:46 +0000 |
| Subject: | Re: Maintainer of Date_Calc | ||
| References: | 1 2 3 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-1315@lists.php.net to get a copy of this message | ||
Colin Viebrock wrote:
>
> > > Anyways, does anybody know any method of converting an arbitary number
> of
> > > days to a correct date, such as '2001-01-40' => '2001-02-09'?
> >
> >
> > list($year, $month, $day) = split('-', $date);
> > while ($day > ($d = DATE_Calc::daysInMonth($month, $year)) {
> > $day -= $d;
> > if ($month++ > 12) {
> > $month = 1;
> > $year++;
> > }
> > }
> > return implode ('-', array($year, $month, $day));
>
> What about:
>
> list($year, $month, $day) = split('-', $date);
> $string = date('Y-m-d', mktime(0,0,0,$month,$day,$year));
>
> mktime() handles the "January 40th" problem itself.
>
mktime is "timestamp" dependant, so it works only with a limited range
of dates (from 1970 to 2037 in 32bits systems). This is a great
limitation as can't handle for example born dates.
Tomas V.V.Cox