?
Solved

Days between two dates

Posted on 2010-11-26
6
Medium Priority
?
413 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
WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

 

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 2000 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

771 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