Link to home
Start Free TrialLog in
Avatar of PeterErhard
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?
Avatar of Harisha M G
Harisha M G
Flag of India image

Avatar of PeterErhard
PeterErhard

ASKER

Thanks for that.

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

Open in new window

Change DATE( ) to TO_DAYS(DATE( ))
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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Harisha M G
Harisha M G
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks very much, that did the trick :)