Forum Moderators: coopster
Imagining your dates are stored as "March 3, 2007":
$expires=strtotime(str_replace(",","",$row['expiry'])); $rightnow=time(); $secondsleft=$expires-$rightnow; $monthsleft=round($secondsleft/2592000); print("Expires in around ".$monthsleft." months.\n"); It would be easier if your dates were being stored as timestamps ...
(I say "around x months" because I just used a 30-day period and didn't take into account exactly which months are involved and their relative lengths.)
(There are 86400 seconds in a day ... 31536000 in a year.)
Take a look at the MySQL date functions:
[dev.mysql.com...]
CURDATE() and DATEDIFF() are possibly what you need.
dc
Change:
$expires=strtotime(str_replace(",","",$row['expiry'])); To:
$expires=strtotime($row['expiry']); Should be all you'd need. (There are no commas in your actual date format, and the one you're using will work fine without modification.)
I'm assuming that this code is being used during the
mysql_fetch_array() or similar function, and that you actually have a row result named 'expiry' and that it has data in it. The code I posted will not work all by itself. It needs to be part of a larger script that gets the real data from the database. ;)