Re: A month of beating a dead horse.
Posted in 1993
In article <1qhiolINN2fg@emory.mathcs.emory.edu> alan@effluvia.den.mmc.com (Alan Popiel) writes: >Hi, Cathy, > >It sounds like we are really pretty much in agreement. Remember I said that >"[date] + 1 month" was vague, not meaningless. "Feb 30" is (almost) meaning- >less; so what we need to do is figure out what "1 month" means as an INTERVAL. > >My first cut of 31 days may have been too simple. How about: > >"[date] + 1 month" := "[date] + [number of days in current month], but not > past [last day of next month]" OK, this is easy to do programmatically. Here's an algorithm (wrapped in a 4GL program that can run standalone) that will first try adding a month directly; if that chokes (7 days out of the year), it will get the first day of the second following month, then subtract 1 day so that you get the last day of the following month: ------------------------------------------------------------------------ main define dv,result datetime year to second define dd, firstofmo, lastofprior date whenever any error continue while (true) prompt "Enter date: " for dd let dv = dd -- convert to datetime let result = dv + 1 units month -- try adding a month if status != 0 -- if out of range, do the hard way then -- get the last day of next month let result = dv + 2 units month -- add 2 months (always works) let firstofmo = mdy(month(result), 1, year(result)) -- DATE of 1st day of second month from now let lastofprior = firstofmo - 1 let result = lastofprior -- convert to datetime end if display "datetime + 1 Popiel-month = ", result display " " end while end main ------------------------------------------------------------------------ >| R. Alan Popiel | Internet: alan@den.mmc.com | -- Alan Denney aland@informix.com {pyramid|uunet}!infmx!aland "I love women. I do, I tell ya. I swear, nothing excites me more than watching a beautiful woman as she slowly takes off all her clothes, then looks at me and says, 'Hey! Get away from that window!'" -- Mark Roberts