Hm... I know '$date->add(new DateInterval('P15D'));' is possible, but it has 
the same problem.

I have to write:

$date = new DateTime()
$date->add(new DateInterval('P' . getDaysToAddMethod() . 'D'));

I think it is very hard to read. Or is it just my personal point of view?


@Nikita: I know what you mean. But how would you add a month to a DateTime?


Best regards
Christian


-----Original Message-----
From: sebastian.krebs.ber...@gmail.com 
[mailto:sebastian.krebs.ber...@gmail.com] On Behalf Of Sebastian Krebs
Sent: Monday, December 10, 2012 1:23 PM
To: PHP internals list
Subject: Re: [PHP-DEV] Improve DateTime Class

Hi,

are you mabe just looking for

$date->add(new DateInterval('P15D'));

?


2012/12/10 Christian Stoller <stol...@leonex.de>

> Hi internals,
>
> what do you think about improving the modification functionality of the
> DateTime class. I always get a cold shiver, when I write something like
> this:
> <?php
> $date = new DateTime()
> $date->modify(‘+15 day’);
>
> In my opinion it would be nicer if one could write:
> $date->modify(15, DateTime::INTERVAL_DAY); // for adding 15 days
> $date->modify(-15, DateTime::INTERVAL_DAY); // for subtracting 15 days
>
> Even better would be to have methods like addDays(), addMonths(), etc.
>
> This would make it cleaner and more readable. You do not have to do
> something like this:
>
> $date = new DateTime();
> $date->modify(getDaysToAddMethod() . " day"); // I am not sure if a '+'
> sign is needed if the value is positive
>
> And it is fully backward compatible.
>
> Best regards
> Christian
>
>


-- 
github.com/KingCrunch

Reply via email to