[ciapug] Dates question
David Champion
ciapug@cialug.org
Mon, 20 Sep 2004 11:34:16 -0500
Chris Hettinger wrote:
> Working with dates still challenges me
>
> $date1 = date('Y-m-d H:i:s'); // current date
> $date2 = X;
>
> I need to know if $date2 is 30 or more days in the future from the
> current date.
>
> If $date2 >= $date1 by 30 days
> echo 'date2 is more than 30 days in the future';
> else
> echo 'date2 within 30 days of date1';
>
>
> ^^--- how do I do this comparison?
From the "more than one way to skin a cat" department...
$dt30 = date("Y-m-d", mktime(0,0,0, date("m"), date("d") + 30, date("Y")));
if ($mydate > dt30) { ...
Tim's method works fine too... IMHO this one is more "readable".
-dc