sabecs
asked on
Convert MySQL date with PHP and check if date has passed.
Hi,
I have an expiry date - MySQL date format 2006-07-14,
can anyone please tell how I can convert this and check if the date has passed or expired with PHP.
Thanks
I have an expiry date - MySQL date format 2006-07-14,
can anyone please tell how I can convert this and check if the date has passed or expired with PHP.
Thanks
Sorry, got the if else logic backward, my fingers are tired.
EXPIRED and Current are reversed!
Or use if ($expires < $rightnow) {
EXPIRED and Current are reversed!
Or use if ($expires < $rightnow) {
ASKER
Thanks for your response, but I would prefer not to use a mysql query to format the date.
I already have a PHP variable set as a my date.
$expdate = '2006-07-14';
I already have a PHP variable set as a my date.
$expdate = '2006-07-14';
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
it is usually a good idea to do the comparison on the db side
select * from table1 where id=$id and thedate < $expired
if a row returned, then it is not expired, if none, then expired
select * from table1 where id=$id and thedate < $expired
if a row returned, then it is not expired, if none, then expired
ASKER
Thanks rbartz, thats exactly what I was after.
$result=mysql_query("SELEC
Do the query, get the array and use:
$expires = $result[expire_date]; //gives us unix timestamp of expiry date
$rightnow = time(); // gives us unix timestamp for rightnow
if ($expires > $rightnow) {
echo "EXPIRED!";
} else {
echo "Current!";
}
R