Re: strtotime
| From: | Ivo F.A.C. Fokkema | Date: | Wed, 25 Oct 2006 07:36:47 +0000 |
| Subject: | Re: strtotime | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-243600@lists.php.net to get a copy of this message | ||
On Tue, 24 Oct 2006 20:36:08 -0400, Ron Piggott (PHP) wrote:
>
> I have used the strtotime command to calculate a week ago (among other
> things) with syntax like this:
>
> $one_week_ago = strtotime("-7 days");
> $one_week_ago = date('Y-m-d', $one_week_ago);
>
> How would you use this command to figure out the last day of the month
> in two months from now --- Today is October 24th 2006; the results I am
> trying to generate are December 31st 2006. I want to keep the same
> result until the end of October and then on November 1st and throughout
> November the result to be January 31st 2007
>
> Ron
My suggestion is:
$date = date('Y-m-t', strtotime('+2 months'));
$date = date('F jS Y', strtotime($date));
Only two lines of code, only four function calls. As you know, there are
many ways to do a thing.
Ivo