Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MySql DateDiff Query

Posted on 2011-03-12
3
Medium Priority
?
732 Views
Last Modified: 2012-06-22
I'm working on a Mysql Query as follows

SELECT  `Symbol` ,  `Date` ,  `AdjClose` ,  `Strike` ,  `Type` , (
`Bid` +  `Ask`
) /2 AS  `Price` , DATEDIFF(  'Expiration',  'Date' ) AS  'Days'
FROM  `IWM`.`OptionData` AS  `OptionData`
WHERE  `AdjClose` -  `Strike` <  '10'
AND  `AdjClose` -  `Strike` >  '-10'
ORDER BY  `Days` DESC
LIMIT 0 , 30

The Problem here is that DateDiff() should Take the difference from the two fields in the table and return the days between the two dates, at least as far as I know, but it only returns NULL.

What do I need to do to return a feild that is the number of days between these two date fields.

Thanks
0
Comment
Question by:_Carthmen_
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 35119054
change:
DATEDIFF(  'Expiration',  'Date' )

into:
DATEDIFF(  `Expiration`,  `Date` )
0
 

Author Comment

by:_Carthmen_
ID: 35119199
I copy pasted your change as:

SELECT `Symbol`, `Date`, `AdjClose`, `Strike`, `Type`, ( `Bid` + `Ask` ) / 2 AS `Price`, DATEDIFF(  `Expiration`,  `Date` ) AS `Days` FROM `IWM`.`OptionData` AS `OptionData` WHERE `AdjClose` - `Strike` < '10' AND `AdjClose` - `Strike` > '-10'

But still no go with it.
0
 

Author Comment

by:_Carthmen_
ID: 35119220
never mind, worked fine, my bad. Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

885 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