Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MySql DateDiff Query

Posted on 2011-03-12
3
Medium Priority
?
725 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

670 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