Re: How to get difference in two dates. Please HELP
Posted in 1998
Hi,
You were absolutely close to the solution!!!
Just enter the precision of the Month to Month variable by typing MONTH
(4) to MONTH which provides You with four digits!
Happy New Year
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
> ===========================================