Re: Maintainer of Date_Calc
| From: | Colin Viebrock | Date: | Tue, 07 Aug 2001 14:07:26 +0000 |
| Subject: | Re: Maintainer of Date_Calc | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-1314@lists.php.net to get a copy of this message | ||
> > 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.
- Colin