okay, im taking a proper look now 😛
The best ways to store times and dates in your database is using the time() format - the time since the 1970 Unix creation.
This puts your time in seconds, which means it can be manipulated easily.
For example, to get a date out of it, what you do is date(format mktime(seconds))
Im a little puzzled over this:
$sql = "SELECT * from ecxsubinfo WHERE DURATION = '30'
AND FROM_DAYS(TO_DAYS('EXPIRE_BASED_ON') + 31) = '$today'
AND CANCELLED = 'NO'";
its this FROM_DAYS(TO_DAYS('EXPIRE_BASED_ON') + 31).
Ok.
If i were you, i would look at mktime() with this one...
where 'EXPIRE_BASED_ON' < time (mktime(0,0,$today,0,-30)
where $today is in the time() seconds. (or you can retrieve today's month, day year etc and -30 from the day)
So thats saying, select where 'EXPIRE_BASED_ON' is less than 30 days ago's second count.
My code wont be perfect, and it requires alot of change to your database. What i would say, is to change it, run a query of getting the date set, and running each individual day month and year value through mktime() and time() - you will need explode() to get the numbers out of the date format you set.
your mktime(EXPIRE_BASED_ON) = '$today' would not work, its in the wrong date format. The function cannot tell which is the month day and year and where to break it. For example, if you game it 01,02,03 it wouldnt have a clue what to do.
See http://uk.php.net/manual/en/function.mktime.php for mktime()
and time ()
http://uk.php.net/manual/en/function.time.php