Monday, October 4, 2010

[sql ]get quarter end date of a given date

/*
Get the quarter end day of the given date if shift is zero
if shift is -1, it gets the previous quarter end day of the given date
if shift is 1, it gets the next quarter end day of the given date
shift can be +/- 1,2,3,...
*/
FUNCTION getQuarterEnd(ai_date IN DATE, shift INTEGER) RETURN DATE IS
BEGIN
return last_day(add_months(trunc(ai_date,'Q'), 2+shift*3));
END getQuarterEnd;

No comments:

Post a Comment