Or, cleaned up a bit:
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 thediff, theoffset thediff = DOW(thedate)-DOW(gomonth(thedate, offset*12)) theoffset = IIF(thediff>3, 7-thediff, thediff) RETURN GOMONTH(thedate, offset*12) + theoffset