date algorithm
Posted in 1999
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
I know i might be pushing it, but can anyone help me out with a simple algorithm for a 4gl function which will receive two dates as arguments and calculate the exact number of months between the two dates. thankx a million austin
Sigh, Caveats: I wrote this little gem 4-6 years ago so you may want to validate it. Basically its "Use at your own risk...." Assumptions: DATE 2 is always greater than DATE1! Let m1 = MONTHS(DATE1) Let y1 = YEARS(DATE1) Let m2 = MONTHS(DATE2) Let y2 = YEARS(DATE2) Then the number of months between the two dates is as follows: results = (y2-y1)*12 - (m1-m2) Its simple, clean and efficient. -Just a little piece of code from your Uncle Mikey. Austin Castro wrote: > I know i might be pushing it, but can anyone help me out with a simple > algorithm for a 4gl function which will receive two dates as arguments and > calculate the exact number of months between the two dates. thankx a million > > austin