How do I query the database 10 days ahead and 10 days behind the current date?

Asked

Viewed 33 times

0

Today I can already do the consultation 10 days ago as shown in the query below, I’m just not able to deploy the 10 days ahead of the current date.

SELECT 
  `vw_saldobancario`.`contaApelido`,
  `vw_saldobancario`.`tipoMovimento`,
  `vw_saldobancario`.`historico`,
  (
    vw_saldobancario.debitosPendentes + vw_saldobancario.debitos
  ) AS debitos,
  (
    vw_saldobancario.creditosPendentes + vw_saldobancario.creditos
  ) AS creditos,
  `vw_saldobancario`.`dataMovimento`,
  `vw_saldobancario`.`conta_bancaria_id`,
  IF (
    creditosPendentes > 0 
    OR debitosPendentes > 0,
    'SIM',
    'NAO'
  ) AS Pendentes 
FROM
  `vw_saldobancario` 
WHERE `dataMovimento`  BETWEEN DATE_ADD(CURRENT_DATE(), INTERVAL -10 DAY) AND CURRENT_DATE()
  AND `conta_bancaria_id` = 3 
GROUP BY `idHistorico`

1 answer

-1


If you think to include current date plus 10 the function is DATE_ADD(date, INTERVAL value addunit). Do not need to include the signal: DATE_ADD(CURRENT_DATE(), INTERVAL 10 DAY)

  • Yes, but this is not the question friend and how I do to have beyond 10 the front also have 10 behind ??

  • WHERE dataMovimento BETWEEN DATE_ADD(CURRENT_DATE(), INTERVAL -10 DAY) AND DATE_ADD(CURRENT_DATE(), INTERVAL 10 DAY)

  • That’s right man, thank you!!

  • Glad I could help you, man!

Browser other questions tagged

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