Pass 'interval' value to date_trunc function in PostgreSQL procedure
0
votes
1
answer
2290
views
I am fetching the **"age"** of **two timestamp columns** (**End and Start**) and further choosing it as **to_char 'MM'** format. So I have the difference of the months from two timestamp columns.
The syntax in the above statement goes like :
i = (select to_char(age(End,Start),'MM'));
interval_value = (select i || ' month');
**Also tried:**
interval_value = i || ' Month'
Now,
Passing the value of 'i' in another function **date_trunc** of PostgreSQL.
xyz = (select date_trunc('month',Start::date) + interval_value::text::interval);
The data types for the above variables are:
i numeric :=0
xyz date;
interval_value varchar;
But it doesn't seem to work.
Is there any alternate approach I could use here. The main idea is to get the difference from two timestamps in months and then further passing the difference into the date_trunc function.
Asked by Pranjal Kaushik
(1 rep)
Mar 18, 2019, 08:28 AM
Last activity: Dec 27, 2024, 07:02 AM
Last activity: Dec 27, 2024, 07:02 AM