Solved

Days between two dates

Posted on 2010-11-26
6
402 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
  • 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now