Solved

MySql DateDiff Query

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…

752 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