On Tue, May 8, 2018 at 9:14 AM, Ted Roche tedroche@gmail.com wrote:
So, do you want a function that returns the second Tuesday in May or one that returns the Tuesday closest to May 8? Both would fit the specs.
Date math was one of my many VFP hobbies. There were lots of date math answers in Ask Advisor.
GOMONTH() gets you to the year you want, then you can use DOW() to figure out the day of the week that date has, then add/subtract to get to the Tuesday you're after.
I know there's a better algorithm to do this, but this might work...
function olddate(thedate, offset) * parameters: thedate: date to start from * offset: number of years offset, positive or negative * returns: nearest date to the offset that falls on the same day of the week local thedow, thenewdow, thediff, theoffset thedow = dow(thedate) thenewdow = dow(gomonth(thedate, offset*12)) thediff = thedow - thenewdow theoffset = iff(thediff>3, 7-thediff, thediff) return gomonth(thedate, offset*12) + thediff