[ciapug] Dates question
Tim Perdue
ciapug@cialug.org
Fri, 17 Sep 2004 16:34:44 -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?
This is some date code from gforge:
$date_list = split('[- :]',$release_date,5);
$release_date =
mktime($date_list[3],$date_list[4],0,$date_list[1],$date_list[2],$date_list[0]);
This rips a date like "2004-09-17 16:43" and makes it into unix time
(seconds since 1970).
You should be able to apply that logic to both of your dates and then test
if (($date2-$date1) > (30*24*60*60)) {
greater than 30 days
}
Tim