If you want, for example, the last Friday of the month you could use
LastDayOfMonth(Date(),"Friday") or LastDayOfMonth(5,2018,"Friday")

Function LastDayOfMonth(tuParm1, tuParm2, tuParm3)

Local ldLastDate,lcDayOfWeek,loDaysOfWeek
ldLastDate = {}
If (Pcount() = 3 And Vartype(tuParm3) = "C") Or (Pcount() = 2 And 
Vartype(tuParm2) = "C")
        lcDayOfWeek = Iif(Pcount()=2,tuParm2,tuParm3)
        If 
InList(lcDayOfWeek,"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
                loDaysOfWeek = CreateObject("Collection")
                loDaysOfWeek.Add(1,"Sunday")
                loDaysOfWeek.Add(2,"Monday")
                loDaysOfWeek.Add(3,"Tuesday")
                loDaysOfWeek.Add(4,"Wednesday")
                loDaysOfWeek.Add(5,"Thursday")
                loDaysOfWeek.Add(6,"Friday")
                loDaysOfWeek.Add(7,"Saturday")
        EndIf
EndIf
Do Case
        Case InList(Vartype(tuParm1),"D","T")
                ldLastDate = Gomonth(tuParm1,1)-Day(tuParm1)
        Case Vartype(tuParm1) = "N" And Vartype(tuParm2) = "N"
                ldLastDate = Date(tuParm2,tuParm1+1,1)-1
EndCase
If Not Empty(ldLastdate) And Not Empty(lcDayOfWeek)
         ldLastDate = ldLastDate - Mod((7-(loDaysOfWeek.Item(lcDayOfWeek) - 
loDaysOfWeek.Item(CDOW(ldLastDate)))),7)
EndIf
Return ldLastDate

-----Original Message-----
From: ProFox [mailto:[email protected]] On Behalf Of Ted Roche
Sent: 20 May 2018 20:32
To: [email protected]
Subject: Re: Fun with date calculations in VFP

On Sun, May 20, 2018 at 1:39 PM, Gene Wirchenko <[email protected]> wrote:

>      thedate=date(9999,12,31)     && Handle this extreme case.

And that, kids, is why we call it "The Y10K crisis..."

-- 
Ted Roche
Ted Roche & Associates, LLC
http://www.tedroche.com

[excessive quoting removed by server]

_______________________________________________
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/sn1pr0201mb185661d072db40956e4d7ef8a1...@sn1pr0201mb1856.namprd02.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