Re: How to get difference in two dates. Please HELP
Posted in 1998
Imran
I remember that this issue has been addressed before. What you need to
do is change the declaration of the numMonths like so:
DECLARE numMonths INTERVAL MONTH(3) TO MONTH;
to get numMonths more than 99 and less than 999.
HTH
Sujit
______________________________ Reply Separator _________________________________
Subject: How to get difference in two dates. Please HELP
Author: imranh@imranweb.com (Imran Hussain) at internet
Date: 12/28/1998 12:00 PM
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
===========================================