php - SQL DATEDIFF with WHERE or BETWEEN operator

I am working on mysql query statement. I have to find day difference between two date. Date one is from my table column and date two is now(). And I need to compare output date must be in a day range like 50 to 80. I have tried with two line below code. But both are not working. Any please can help ..
SELECT DATEDIFF(DAY, '2012-01-01', GETDATE()) AS d WHERE d>50 AND d<80
SELECT DATEDIFF(DAY, '2012-01-01', GETDATE()) AS d WHERE d BETWEEN 50 AND 80
Answer
Solution:
Thefrom
clause cannot use aliases defined in theselect
clause. You need to repeat the expression, or use a subquery or cte.
If you are running SQL Server (as your code suggests):
select datediff(day, '2012-01-01', getdate()) as d
from ... -- you should have a "from" clause
where datediff(day, '2012-01-01', getdate()) between 50 and 80
In MySQL (as the tag on your question indicates):
select datediff(current_date, '2012-01-01') as d
from ...
where datediff(current_date, '2012-01-01') between 50 and 80
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: unable to determine current zabbix database version: the table "dbversion" was not found.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.