Ted's solution works just fine. What I didn't test yet is using leap day itself 
as the starting point. Hmmm.....

**************************************
*      Program: datestuff3.prg
*         Date: 05/08/2018 11:09 AM
*  VFP Version: Visual FoxPro 09.00.0000.7423 for Windows
*        Notes: 
**************************************
ACTIVATE SCREEN 
CLEAR 
? [Today:  ]+CHR(9)+CHR(9)
?? DATE()
?? CHR(9)+CDOW(DATE())
? [Same day last year:  ]
?? olddate(DATE(),-1)
?? CHR(9)+CDOW(olddate(DATE(),-1))
? [Same day 2 years ago:  ]
?? olddate(DATE(),-2)
?? CHR(9)+CDOW(olddate(DATE(),-2))
? [Same day 3 years ago:  ]
?? olddate(DATE(),-3)
?? CHR(9)+CDOW(olddate(DATE(),-3))
? [Same day 10 years ago:  ]
?? olddate(DATE(),-10)
?? [ ]+CDOW(olddate(DATE(),-10))
? [Yesterday:  ]+CHR(9)
?? DATE()-1
?? CHR(9)+CDOW(DATE()-1)
? [Same day last year:  ]
?? olddate(DATE()-1,-1)
?? CHR(9)+CDOW(olddate(DATE()-1,-1))
? [Same day 2 years ago:  ]
?? olddate(DATE()-1,-2)
?? CHR(9)+CDOW(olddate(DATE()-1,-2))
? [Same day 3 years ago:  ]
?? olddate(DATE()-1,-3)
?? CHR(9)+CDOW(olddate(DATE()-1,-3))
? [Same day 10 years ago:  ]
?? olddate(DATE()-1,-10)
?? [ ]+CDOW(olddate(DATE()-1,-10))
? [Tomorrow:  ]+CHR(9)
?? DATE()+1
?? CHR(9)+CDOW(DATE()+1)
? [Same day last year:  ]
?? olddate(DATE()+1,-1)
?? CHR(9)+CDOW(olddate(DATE()+1,-1))
? [Same day 2 years ago:  ]
?? olddate(DATE()+1,-2)
?? CHR(9)+CDOW(olddate(DATE()+1,-2))
? [Same day 3 years ago:  ]
?? olddate(DATE()+1,-3)
?? CHR(9)+CDOW(olddate(DATE()+1,-3))
? [Same day 10 years ago:  ]
?? olddate(DATE()+1,-10)
?? [ ]+CDOW(olddate(DATE()+1,-10))

FUNCTION oldDate(theDate AS Date, offset AS Integer)
* compliments of Ted Roche
* 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 m.theDiff, m.theOffset
m.theDiff=DOW(m.theDate)-DOW(GOMONTH(m.theDate, m.offset*12))
m.theOffset=IIF(theDiff>3, 7-m.theDiff, m.theDiff)
RETURN GOMONTH(m.theDate, m.offset*12) + m.theOffset

ENDFUNC

--

rk

-----Original Message-----
From: ProfoxTech <[email protected]> On Behalf Of Gene Wirchenko
Sent: Tuesday, May 08, 2018 12:46 PM
To: [email protected]
Subject: RE: Fun with date calculations in VFP

At 06:27 2018-05-08, Richard Kaye <[email protected]> wrote:
>The latter. And that was the approach I was just working through.

      What about the week every few years that you will be disregarding?

      A year has 52 weeks plus one or two days.

[snip]

Sincerely,

Gene Wirchenko


_______________________________________________
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/dm5pr10mb1244761defc7089d74f1fc26d2...@dm5pr10mb1244.namprd10.prod.outlook.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.

Reply via email to