Solved

MySql DateDiff Query

Posted on 2011-03-12
3
721 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_
[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
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
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…

635 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