Solved

Days between two dates

Posted on 2010-11-26
6
411 Views
Last Modified: 2012-05-10
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?
0
Comment
Question by:PeterErhard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 37

Expert Comment

by:Harisha M G
ID: 34220721
0
 

Author Comment

by:PeterErhard
ID: 34220726
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

0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 34220731
Change DATE( ) to TO_DAYS(DATE( ))
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Author Comment

by:PeterErhard
ID: 34220735
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

0
 
LVL 37

Accepted Solution

by:
Harisha M G earned 500 total points
ID: 34220752
Sorry.. it should be CURDATE()

SELECT DateCreated, TO_DAYS(CURDATE()) - TO_DAYS( DateCreated )
FROM TABLE
LIMIT 0 , 30;

0
 

Author Comment

by:PeterErhard
ID: 34220756
Thanks very much, that did the trick :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question