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');
interval_value = i || ' Month'
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.