Select between dates in Mysql

5

Good afternoon,

I have the following problem:

I have a DATA_ENTRATE column of type date and I need a select that compares to DATA_ENTRATE and the " current date " (eg today is 28/08/2015, tomorrow would be 08/29/2015), and return me only the records with the in_data> > = 90 days

If anyone can help me, thank you, I tried everything but without success.

    
asked by anonymous 28.08.2015 / 21:36

4 answers

8

Just calculate the difference between the desired field and the current date ( now ) in the where.

As it is not clear what you want, then follow the two possible solutions:

90 days prior to "today"

SELECT * FROM dados WHERE DATEDIFF(now(), data_entrada) >= 90

See working in SQLFiddle .

90 days after "today"

SELECT * FROM dados WHERE DATEDIFF(data_entrada, now()) >= 90

See working in SQLFiddle .

Just change the order of DATEDIFF parameters that solves both problems.

    
28.08.2015 / 21:43
6
WHERE DATE_SUB(data_atual,INTERVAL 90 DAY) >= data_entrada

This returns only dates that are 90 days or more before the current date

    
28.08.2015 / 21:43
5
select * from suaTabela where data_entrada >= DATE_ADD(curdate(),INTERVAL 90 DAY);

Explanation: DATE_ADD( param1, INTERVAL 90 DAY ) , where param1 would be the current date and the second parameter would be the number of days in the case is 90.

I made a Luis Enrique Fork to explain the divergence in SQL Fiddle as far as I understand from now() or% with% of records that would be current date greater than 90 days.

    
28.08.2015 / 21:42
0

Have you tried using CURDATE() + INTERVAL 90 DAY ?

    
28.08.2015 / 21:46