Re: How to get difference in two dates. Please HELP
Posted in 1998
Try:
DEFINE numMonths INTERVAL MONTH(9) TO MONTH;
^^^
Imran Hussain wrote:
>
> Hi,
> I need to subtract two dates from each other and get the difference in
> MONTHS not DAYS. So lets say I have the following:
>
> dt1 = '12/1/1998'
> dt2 = '7/15/1998'
> dt3 = dt1 - dt3 dt3 should be 5
>
> How do I do that.
>
> I wrote a stored procedure to do this but it only works if the
> difference in months is less than 100 months. The code is given below.
>
> create procedure GetMonthDiff(st DATE, ed DATE)
> returning int;>
> DEFINE s CHAR(20);
> DEFINE numMonths INTERVAL MONTH TO MONTH;
>
> let numMonths = EXTEND(st, YEAR TO MONTH) - EXTEND(ed, YEAR TO MONTH);
>
> let s = numMonths;
> return TRIM(s);
>
> END PROCEDURE;
>
> --
> ===========================================
> Imran Hussain
> MCP, MCSD
> imranh@imranweb.com
> http://www.imranweb.com
> ===========================================
--
________________________________________________________________
John H. Frantz Power-4gl: Extending Informix-4gl
john@rl.is http://www.rl.is/~john/pow4gl.html