Add days to a date in mysql and compare it to the current date?

Asked

Viewed 166 times

-1

I have some conditions on a page of my system, I need to put something in my SELECT so that on his own SELECT has already entered a certain condition.

The condition is as follows, I need these two points to be true:

  1. If the payment date is equal to 0000-00-00
  2. If it passed 30 days after the date of issuance, and that "predefined" day is smaller (smaller because it would have already ended the period of 1 month) than today’s date.

One hypothesis of mine was to add + 30 days on payment date and compare with today’s date, but I don’t even know if I can do it in a SELECT.

 SELECT nota_fiscal, emissao, valor, pagamento FROM emissao_nf WHERE pagamento = '0000-00-00'
   

It is possible to add days to all the dates that are registered and still compare with today’s date, all in one SELECT?

How can I be doing it this way or even another?

1 answer

1


What you need to be able to "join" 2 conditions is an "OR". For the date, it is possible to add. Vc can do "date" + INTERVAL 30 DAY.

example: SELECT pagamento FROM emissao_nf WHERE pagamento = '0000-00-00' OR pagamento + INTERVAL 30 DAY > CURDATE()

You can try this query here: http://sqlfiddle.com/#! 9/869203/5

  • It worked, in this case I didn’t use the OR and yes the AND, needed both conditions, thanks! + 1

  • In this case I think your query should be about payment = '0000-00-00' (indicating that there was no payment) AND a check on the issue, or payment deadline. By the question it seemed that both its conditions were on the pay column. @Samuel

  • Yes, 0000-00-00 indicating that there was no payment and a check on the date of issue. In his reply, I only exchanged the OR for AND and emissao + INTERVAL 30 DAY < CURDATE()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.