RE: [PHP] Comparing two dynamic dates
| From: | Ford, Mike [LSS] | Date: | Wed, 13 Mar 2002 17:56:04 +0000 |
| Subject: | RE: [PHP] Comparing two dynamic dates | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-88379@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Erick [mailto:soundguy4jc@yahoo.com]
> Sent: 12 March 2002 01:47
>
>
> I've been working on this for a little while now, without success. I
> want to compare the current date to a certain recurring date (ie:
> compare todays date to the date of the second Sunday of the a certain
> month). I have an event that happens on the second Sunday of
> each month,
> and I want to show the next date on which the event occurs,
> without just
> listing the next few months. Can anyone help?
Amazingly, I believe the following will do the trick:
$second_sun_next_month = strtotime('2sunday', strtotime('+month 1
'.date('F')));
Or, breaking it down into understandable chunks:
$this_month = date('F'); // 'March', as I write this!
$first_of_next_month = strtotime("+month 1 ${this_month}");
// interpreted by strtotime as "one month after the 1st of this month" -- i.e. 1st
April
// returned value is a UNIX timestamp
$second_sun_next_month = strtotime('2sunday', $first_of_next_month);
// returns date of second Sunday counting from 1st of next month.
strtotime is actually quite a powerful beast, especially in its range of "relative" dates
-- go to http://uk.php.net/manual/en/function.strtotime.php
and follow the "Date Input Formats" link to get the full picture.
HTH
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211