Jump to content
Fórum Script Brasil
  • 0

60 dias antes mysql


Aminadabe

Question

Olá, estou fazendo um sistema, e preciso trazer alguns dados antes do vencimento, na verdade 60 dias antes do vencimento, já tentei de tudo o que eu sabia com mysql, más sem sucesso, o que fazer ajudem, segue as queryes que eu tentei.

SELECT * FROM mensagens WHERE mensagens.periodoRenovacao >= DATE_SUB(CURDATE(), INTERVAL 60 DAY) order by lidoAdmin desc


SELECT  mensagens.dataRenovacao BETWEEN CURDATE() + INTERVAL 60 DAY AND CURDATE() from mensagens

 

Sou novo aqui neste fórum, me ajudem.

 

 

 

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

USE test;

CREATE TABLE DEMO(
    ID INT NOT NULL AUTO_INCREMENT,
    VENCIMENTO DATE,
    CONSTRAINT PK_DEMO PRIMARY KEY(ID)
)

INSERT INTO DEMO (VENCIMENTO) VALUES('2016-01-11');
INSERT INTO DEMO (VENCIMENTO) VALUES('2016-01-12');
INSERT INTO DEMO (VENCIMENTO) VALUES('2016-01-13');

SELECT 
    NOW(), 
    DATE_SUB(VENCIMENTO, INTERVAL 60 DAY), 
    VENCIMENTO 
FROM 
    DEMO 
WHERE 
    VENCIMENTO BETWEEN DATE_SUB(VENCIMENTO, INTERVAL 60 DAY) AND NOW()
ORDER BY 
    ID ASC;

 

Link to comment
Share on other sites

  • 0
SELECT 
    ID,
    VENCIMENTO,
    DATEDIFF(NOW(), VENCIMENTO)
FROM 
    DEMO 
WHERE
    DATEDIFF(NOW(), VENCIMENTO) <= 60
ORDER BY 
    ID ASC;

Alternativa!

SELECT 
    ID,
    VENCIMENTO,    
    DATEDIFF(NOW(), DATE_SUB(NOW(), INTERVAL 60 DAY)) AS VENCIMENTO_MINIMO,        
    DATEDIFF(NOW(), VENCIMENTO) AS DIFERENCA_DIA
FROM 
    DEMO 
WHERE
    DATEDIFF(NOW(), VENCIMENTO) <= 60
ORDER BY 
    ID ASC;

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      651.8k
×
×
  • Create New...