PeterErhard
asked on
Days between two dates
I'm trying to compare two days that I pull out of a mysql query and get the difference between them
i.e. the number of days between 2008-01-27 and 2009-04-25.
Is there a simple way of doing this?
i.e. the number of days between 2008-01-27 and 2009-04-25.
Is there a simple way of doing this?
ASKER
Thanks for that.
How come this doesn't work?
How come this doesn't work?
Error
SQL query:
SELECT DateCreated, DATE( ) - TO_DAYS( DateCreated )
FROM TABLE
LIMIT 0 , 30
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') - TO_DAYS( DateCreated )
FROM AskTheSpider
LIMIT 0, 30' at line 1
Change DATE( ) to TO_DAYS(DATE( ))
ASKER
Getting this now. Any Ideas?
SQL query:
SELECT DateCreated, TO_DAYS( DATE( ) ) - TO_DAYS( DateCreated )
FROM AskTheSpider
LIMIT 0 , 30
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) - TO_DAYS(DateCreated)
FROM AskTheSpider
LIMIT 0 , 30' at line 1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much, that did the trick :)
http://www.plus2net.com/sql_tutorial/date_difference.php
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html