need help with date compare

I'm trying to retrieve an expiration date from a database and compare it to today's date. If the expiration date hasn't arrived yet, I want to redirect the program, if if it has I want to display a message.

mysql_select_db(expiredb) or die( "Unable to select database");
$noticedate = $_POST['noticedate'];
$expiredate = $_POST['expiredate'];
$query="SELECT noticedate,expiredate FROM entrydata";
$todays_date = date("Y-m-d");
$today = strtotime($todays_date);
$expiration_date = strtotime($expiredate);
if ($expiration_date > $today) {

header("Location: hammockoaks.html");
elseif ($expiration_date = $today) {
header("Location: hologo.html");
}else {
}// end of it statement for 'results found'
echo '_POST["submit"] is actually empty.';
}// end of if statement for no 'submit'
You are trying to retrieve all the records, but in your case you will redirect in particular case only. I mean a particular record you will check against expire date and then redirect.

It is always better to use the query to collect the records than collect the record and then compare. So your query should be like this.

SELECT noticedate,expiredate FROM entrydata where expiredate > CURDATE()

This will display all records for which expire date is not yet arrived. You can change this to get all records which are expiring today.

SELECT noticedate,expiredate FROM entrydata where expiredate = CURDATE()

the only retrieval I'm making is the expiration date from the database. Then I want to execute one program or the other depending on whether the expiration date has been reached.
There are problems in the code.
1. You are getting the noticidate & expiredate from the form posting by not using inside the query. Query should be
select expiredate from entrydate where noticedat = '$noticedate'

2. You have to use mysql_fetch_object to get the expiredate and then you need not convert it into string, directly you can match with today.
until I get this going I'm not even using the noticedate field
Please Login to post your reply or start a new topic