All Forums Database
Natalia 4 posts Joined 10/04
08 Feb 2006
Month difference

Hi!Someone knows how to calculate month difference between two dates?For example:=> date '2006-01-01' - date '2006-03-01' = 2 monthsI know that I could calculate by division, but it could be not exactly.=> date '2006-01-01' - date '2006-03-01' /30Thanks a lot.Natalia.

08 Feb 2006

date '2006-01-01' - date '2006-03-01' is not 2 it is -2try this select date '2006-03-01' - date '2006-01-01' month as ActualMonthsthe result will be 2but the problem with this operation is select date '2006-03-22' - date '2006-01-01' month as ActualMonthsthe answer is 2 again. It will not display the data as 2 months XX days.

Natalia 4 posts Joined 10/04
08 Feb 2006

Thanks. :-)

Sathish 3 posts Joined 11/05
10 Feb 2006

select (extract (year from '2006-03-22' )-extract(year from '2005-01-01'))*12 + extract (month from '2006-03-22') - extract (month from '2005-01-01')14 monthsselect (extract (year from '2006-01-22' )-extract(year from '2005-03-01'))*12 + extract (month from '2006-01-22') - extract (month from '2005-03-01')10 monthsThanks,ksheersagar

You must sign in to leave a comment.