Tuesday, 3 January 2023

Postgresql - Get the last 'X' months

To get the last 'x' months from the current date,

Method 1:

SELECT date_trunc('month', current_date - interval '4' month) as mydate

e.g. Current date is, 2022-01-03 19:30:00

Output is, 2022-09-01 00:00:00

Method 2:

SELECT CURRENT_DATE - INTERVAL '4 months' as mydate

e.g. Current date is, 2022-01-03 19:30:00

Output is, 2022-09-03 00:00:00

DBT - Models

Models are where your developers spend most of their time within a dbt environment. Models are primarily written as a select statement and ...