TWO months of flogging dead horses = dog meat
Posted in 1993
Sent this to Alan some time ago, as long as we're parading month arithmetic, here's my solution. No warranty implied or expressed. } I think that adding 1:n months to a date should be handled by the developer in } a subroutine. I would do it by: } } add_month(date, months) } } define stuff } } month_days array[12] of smallint } } let month_days[1] = 31 } let month_days[2] = 28 } ........ } } let year = year(date) } let month = month(date) } let day = day(date) } } let month = month + months } } # roll to proper year } while month > 12 } let year = year + 1 } let month = month-12 } end while } } # want to handle negative months as well - so } while month < 0 } let year = year - 1 } let month = month+12 } end while } Alan replied that he stuck an 'if month = 2' here. } # how many days in feb? } if year mod 4 = 0 then } if year mod 100 = 0 then } if year mod 400 = 0 then } let month_days[2]=month_days[2]+1 # no else, already = 28 } end if } else } let month_days[2]=month_days[2]+1 } end if } end if } # is day valid? } # since this is MONTH arithmetic, don't roll } # extra days into the next month. } if day > month_days[month] then } let day = month_days[month] } end if } } let new_date = mdy(month, day, year) } return new_date } } end function } _____________________________________________________________________________ Jack Parker - Contractor | Hewlett Packard, BSMC Boise, Idaho, USA| So many threads, so little time jparker@hpbs2561.boi.hp.com | (208) 396-5388 (W) (208) 384-1623 (H) | _____________________________________________________________________________