Generate file D-1

0

How do I select data in D-1 format (current day - 1), what would VBA be a AGORA() - 1 , how would this be in postgreSQL?

I have the following query and would like to get the day from yesterday to generate reports.

select * 
from 
    ivr_contatos, 
    ivr_campanha,
    ivr_business 
where ivr_campanha.id = '1' 
    and ivr_contatos.campanha = '1' 
    and ivr_business.idvisita = ivr_contatos.codigo 
    and ivr_contatos.status = 0 
    and tentativas >= qtdtentativas 
    and date();
    
asked by anonymous 25.06.2018 / 15:13

1 answer

1

The CURRENT_DATE can be used that returns the current date. If you need the date and time use CURRENT_TIMESTAMP .

select * 
from 
    ivr_contatos, 
    ivr_campanha,
    ivr_business
where ivr_campanha.id = '1' 
    and ivr_contatos.campanha = '1' 
    and ivr_business.idvisita = ivr_contatos.codigo 
    and ivr_contatos.status = 0 
    and tentativas >= qtdtentativas 
    and nome_do_campo = CURRENT_DATE - interval '1 day';

There are other possibilities such as setting the interval ( interval ) that you want to add or subtract in your query, if for example you need the date of the previous month, you could perform the query as below:

select * 
from 
    ivr_contatos, 
    ivr_campanha,
    ivr_business
where ivr_campanha.id = '1' 
    and ivr_contatos.campanha = '1' 
    and ivr_business.idvisita = ivr_contatos.codigo 
    and ivr_contatos.status = 0 
    and tentativas >= qtdtentativas 
    and nome_do_campo = CURRENT_DATE - interval '1 month';

link

    
25.06.2018 / 15:51