views:

72

answers:

2

I need to compare a MySQL datetime with the current time, to get the dateDiff to show a messange if the MySQL datetime, is less than 30 days from today.

I'm using codeigniter, and I tried a lot of helpers, and lots of thing, I just can't get to work.

Some people says that is better to save in database a timespan, I just don't know wich one is the best aproach.

Thanks in advance!

EDIT: I'm looking for a CI code, or a Mysql Code, or both, to get it to work. It doesn't matter where i get the current date (could be mysql or server time). Also, I have the needed code on the view, and the controller, I just need some model code to get it, or MySql code

+1  A: 
SELECT DATE_DIFF(CURDATE(),your_mysql_date_field) FROM your_table
Narf
It's DATEDIFF, but it's working perfectly... thanks
josecortesp
+1  A: 

Check out the PHP date_diff() function, for example:

$datetime1 = date_create('2009-10-11');
$datetime2 = date_create('2009-10-13');
$interval = date_diff($datetime1, $datetime2);
echo $interval->format('%R%d days');

The above example will output:

+2 days

You can get the current time using getdate().

Mitchell McKenna