Query per month in PostgreSQL [closed]

0

Good day to the community, my question is how I can make a query to a specific table based on the current month, I want to get the record of the first day until the last day of the month, no matter what day of the current month we let's find, I'd really appreciate your help.

    
asked by Brian Rodriguez 20.08.2018 в 18:29
source

1 answer

3

Try the functions of date_trunc and extract .

To get the first day of the current month you do it with:

select extract (day from (select date_trunc('month',current_date)))  

To get the last day of the current month, you do it with:

select extract (day from (select date_trunc('month',current_date) +'1month' ::interval -'1sec' ::interval))

I think you could save those values in some variables and use them in your query .

    
answered by 20.08.2018 в 18:42