Click to See Complete Forum and Search --> : comparing dates


nuthead
06-11-2003, 02:52 PM
I need to know how to compare a date with a text string taken from a flat-file. The flat-file will contain a date string (in whatever format is required) and it needs to be compared with the current date, if the current date is past the one in the file it will delete the file. I can code the second part, its the first part im having problems with.

I'd play with all of PHP's different date settings buy my server has gone tits up at the mo so i thought it would be easier to ask you guys!

Thanks...

pyro
06-11-2003, 03:32 PM
Something like this should be close...

<?PHP

$date = "06-11-2003";

$today = date("m-d-Y"); #return today's date as MM-DD-YYYY

if ($today == $date) {
echo '$today is the same as $date';
}
else {
echo '$today is not the same as $date';
}

?>

nuthead
06-11-2003, 03:39 PM
thanx pyro but it needs to be if it's equal or greater than today's date, thats what i cant work out.

pyro
06-11-2003, 03:46 PM
A bit tougher, but not too bad...

<?PHP

$today = time(); #today's date in seconds since January 1, 1970
$date = "06-11-2003";
$d = split("-",$date);
$date_seconds = mktime(0,0,0,$d[0],$d[1],$d[2]); #turn $date into seconds since January 1, 1970
if ($today > $date_seconds) {
echo ("Delete the file");
}
else {
echo ("Don't delete the file");
}

?>

nuthead
06-11-2003, 03:48 PM
You the man pyro! :D

Originally posted by pyro
A bit tougher, but not too bad...

<?PHP

$today = time(); #today's date in seconds since January 1, 1970
$date = "06-11-2003";
$d = split("-",$date);
$date_seconds = mktime(0,0,0,$d[0],$d[1],$d[2]); #turn $date into seconds since January 1, 1970
if ($today > $date_seconds) {
echo ("Delete the file");
}
else {
echo ("Don't delete the file");
}

?>

pyro
06-11-2003, 03:53 PM
Thanks... :D

tosbourn
08-04-2006, 03:00 AM
Just found this on Goggle when having the same problems - pyro - over 2 years on and you are still the man.

hartnell
10-26-2006, 02:21 PM
Same issue - found this via Google and had to register just to say thanks - worked as it should!