Get data for the previous month in postgresql

SELECT *
FROM Conference WHERE date_start ---don't know how to proceed---

How to check whether date_startthere was a previous month? Thank you.

+4
source share
1 answer

Subtract one month from the current month, and then “truncate” it before the start of this date. Since you do not want to include lines from the "this" month, you also need to add a condition for this

SELECT *
FROM Conference 
WHERE date_start >= date_trunc('month', current_date - interval '1' month)
  and date_start < date_trunc('month', current_date)

date_trunc('month', current_date - interval '1' month)will return the 1st day of the previous month, and date_trunc('month', current_date)will return the first day of the month "this".

+10
source

All Articles