On Tue, May 8, 2018 at 9:14 AM, Ted Roche <[email protected]> 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 _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/CACW6n4u4nczhZe8=v3n2zcnattpn2tjdvmdigxbxorpe8xi...@mail.gmail.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

