Click here to Skip to main content
15,123,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my case,
I want to get last 6 months records from the current date using squelize query in the node and want to group by number of records of each month.
please help me

What I have tried:

I want to get last 6 months records from the current date using squelize query in the node and want to group by number of records of each month.
Posted
Updated 25-Aug-21 18:34pm

1 solution

First, you have to find out the date that is six month older than now, to achieve this, use INTERVAL in PostgreSQL like this:
JavaScript
CURRENT_DATE - INTERVAL '6 months'

Now, you can retrieve all records that is older than this six-month-old date. i.e.
SELECT * from tablename where datefield >  CURRENT_DATE - INTERVAL '6 months'

You should familiarize yourself with PostgreSQL: Documentation: 8.2: Date/Time Functions and Operators[^]
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900