You could try the months_between
function. It will calculate the number of months between two dates, as a decimal number.
select months_between(sysdate+30, sysdate ) from dual;
select months_between(sysdate+15, sysdate ) from dual;
In this example, the first paramater is greater than the second so it will return 1. The second line returns ~0.48 (when executed at about 11:30 AM on 2010-09-01) To get the actual date values:
select case when months_between(sysdate+30, sysdate ) > 0 then sysdate+30 else sysdate end from dual;
In general:
case when months_between(dateA, dateB ) > 0 then dateA else dateB
Update:
After some experimentation, it seems the finest granularity of this function is Day.
select months_between(to_date('2010-10-16 23:59:59', 'YYYY-MM-DD HH24:MI:SS'),
to_date('2010-10-16 00:00:00', 'YYYY-MM-DD HH24:MI:SS'))
from dual;
...will return 0
but
select months_between(to_date('2010-10-17 00:00:00', 'YYYY-MM-DD HH24:MI:SS'),
to_date('2010-10-16 00:00:00', 'YYYY-MM-DD HH24:MI:SS'))
from dual;
will return 0.032258064516129.
Some other interesting date difference/compare techniques here: http://www.orafaq.com/faq/how_does_one_get_the_time_difference_between_two_date_columns