7
I need to catch the difference of two months dates, for example 16/03/2013 until the date 16/07/2014. If I do
select extract('Month' from age(data1, data2))
What will return is a result 4
, as it informs that the difference between the date is 1 year of 4 months.
But what I need is total in months, 15
months apart. There is some way?
I actually had a problem with the date, the month if I have using last year’s negative date. For example,
(DATE_PART('month', now()) - DATE_PART('month', '12/12/2013':timestamp))
.– lionbtt
Which is the expected result?
12/2013
for08/2014
. First account= 1 ano = 12 meses
. Second account: August to December= 8 - 12 = -4 meses
. of12/2013
until08/2014
=12 - 4
=8 meses
.– Anthony Accioly
Anyway, if you always want absolute values you can use the function
abs(x)
or ensure that the longest date is always used asdata2
in hisselect
. Otherwise you will have cases like12/2013 - 08/2014
whose result will return, correctly,-8
months.– Anthony Accioly