jai
jai

Reputation: 305

How can I find the difference between two dates in MySQL?

How can I find the difference between two dates in MySQL?

Upvotes: 2

Views: 1683

Answers (3)

xkeshav
xkeshav

Reputation: 54084

learn DATEDIFF

eg :     SELECT DATEDIFF('2007-12-31 23:59:59','2007-12-30');

Upvotes: 0

Neo
Neo

Reputation: 5463

mysql> select current_date()>'2011-01-01 12:01:01';
+--------------------------------------+
| current_date()>'2011-01-01 12:01:01' |
+--------------------------------------+
|                                    1 |
+--------------------------------------+
1 row in set (0.00 sec)

mysql> select '2011-01-01 12:01:01' > current_date();
+----------------------------------------+
| '2011-01-01 12:01:01' > current_date() |
+----------------------------------------+
|                                      0 |
+----------------------------------------+
1 row in set (0.00 sec)

mysql> 

Upvotes: 0

Owen Fraser-Green
Owen Fraser-Green

Reputation: 787

DATEDIFF returns the difference in days between two dates:

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_datediff

Upvotes: 2

Related Questions