1

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

4
  • 1
    What are you looking for, a mySQL query or CI code? Commented Oct 7, 2010 at 22:57
  • Any of those... Even advise on how to get it to work. Commented Oct 7, 2010 at 23:57
  • Why don't you show us your code? Commented Oct 8, 2010 at 0:09
  • 1
    I'm calling it a day for today so I can't write a full solution but what you need will be possible to do using the mySQL Date and time functions: NOW() / DATE_SUB() / DATE_ADD()/ maybe DATE_DIFF() Commented Oct 8, 2010 at 0:16

2 Answers 2

2
SELECT DATEDIFF(CURDATE(),your_mysql_date_field) FROM your_table 
Sign up to request clarification or add additional context in comments.

Comments

2

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().

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.