Solved

MySql DateDiff Query

Posted on 2011-03-12
3
691 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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
change:
DATEDIFF(  'Expiration',  'Date' )

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

Author Comment

by:_Carthmen_
Comment Utility
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_
Comment Utility
never mind, worked fine, my bad. Thanks
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

16 Experts available now in Live!

Get 1:1 Help Now