SELECT * FROM Conference WHERE date_start ---don't know how to proceed---
How to check if date_start
has been in the previous month ? Thanks you.
How to get last 3 months records from the table. SELECT * from table where month > CURRENT_DATE-120 and month < CURRENT_DATE order by month; I have used the above query is it correct?
You can select the last day of month. SELECT (date_trunc('MONTH', ('201608'||'01')::date) + INTERVAL '1 MONTH - 1 day')::DATE; 201608 is replaceable with a variable.
What is PostgreSQL Now Function? The Now() function is used to return the current date and time of the time zone (default or user-defined). Its return type is the timestamp with the time zone.
Subtract one month from the current month, then "truncate" that to the beginning of that date. As you don't want to include rows from "this" month, you also need to add a condition for that
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 "this" month.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With