On 2018-05-16 18:02, Ted Roche wrote:
LastDayOfMonth() or LDOM back in my 8.3 days, was always a popular request:
http://fox.wikis.com/wc.dll?Wiki~FindingTheLastDayOfTheMonth~VB
Ed Leafe had shared a ton of date functions for VFP years ago. Here's what I have in my framework from Ed:
FUNCTION FirstDayOfMonth(tdDate as Date) as Date if PARAMETERS()=0 then tdDate = date() endif return (tdDate - (DAY(tdDate)-1)) ENDFUNC && FirstDayOfMonth
FUNCTION FirstDayOfQuarter(tdDate as Date) as Date LOCAL lcDate as String, lcMonth as String, lcYear as String, ldDate as Date if PARAMETERS()=0 then tdDate = date() endif lcDate = DTOS(tdDate) lcMonth = SUBSTR(lcDate,5,2) lcYear = LEFT(lcDate,4) DO CASE CASE BETWEEN(VAL(lcMonth),1,3) lcDate = "01/01/" + lcYear CASE BETWEEN(VAL(lcMonth),4,6) lcDate = "04/01/" + lcYear CASE BETWEEN(VAL(lcMonth),7,9) lcDate = "07/01/" + lcYear OTHERWISE && CASE BETWEEN(VAL(lcMonth),10,12) lcDate = "10/01/" + lcYear ENDCASE ldDate = CTOD(lcDate) return ldDate ENDFUNC && FirstDayOfQuarter
FUNCTION LastDayOfQuarter(tdDate as Date) as Date LOCAL lcDate as String, lcMonth as String, lcDay as String, ldDate as Date if PARAMETERS()=0 then tdDate = date() endif lcDate = DTOS(tdDate) lcMonth = SUBSTR(lcDate,5,2) lcYear = LEFT(lcDate,4) DO CASE CASE BETWEEN(VAL(lcMonth),1,3) lcDate = "01/31/" + lcYear CASE BETWEEN(VAL(lcMonth),4,6) lcDate = "04/30/" + lcYear CASE BETWEEN(VAL(lcMonth),7,9) lcDate = "07/31/" + lcYear OTHERWISE && CASE BETWEEN(VAL(lcMonth),10,12) lcDate = "10/31/" + lcYear ENDCASE ldDate = CTOD(lcDate) return ldDate ENDFUNC && LastDayOfQuarter
FUNCTION FirstDayOfYear(tdDate as Date) as Date LOCAL lcDate as String, lcYear as String, ldDate as Date if PARAMETERS()=0 then tdDate = date() endif lcDate = DTOS(tdDate) lcYear = LEFT(lcDate,4) lcDate = "01/01/" + lcYear ldDate = CTOD(lcDate) return ldDate ENDFUNC && FirstDayOfYear
FUNCTION LastDayOfYear(tdDate as Date) as Date LOCAL lcDate as String, lcYear as String, ldDate as Date if PARAMETERS()=0 then tdDate = date() endif lcDate = DTOS(tdDate) lcYear = LEFT(lcDate,4) lcDate = "12/31/" + lcYear ldDate = CTOD(lcDate) return ldDate ENDFUNC && LastDayOfYear
FUNCTION LastDayOfMonth(tdDate as Date) as Date if PARAMETERS()=0 then tdDate = date() endif return (GOMONTH(tdDate,1) - DAY(GOMONTH(tdDate,1))) ENDFUNC && LastDayOfMonth
FUNCTION FirstDayOfWeek(tdDate as Date) as Date if PARAMETERS()=0 then tdDate = date() endif return (tdDate - (DOW(tdDate)-1)) ENDFUNC && FirstDayOfWeek
FUNCTION LastDayOfWeek(tdDate as Date) as Date if PARAMETERS()=0 then tdDate = date() endif return (tdDate + (7 - DOW(tdDate))) ENDFUNC && LastDayOfWeek
FUNCTION LastMonthDate(tdDate as Date) as Date if PARAMETERS()=0 then tdDate = date() endif return (GOMONTH(tdDate,-1)) ENDFUNC && LastDayOfWeek
FUNCTION NextMonthDate(tdDate as Date) as Date if PARAMETERS()=0 then tdDate = date() endif return (GOMONTH(tdDate,1)) ENDFUNC && LastDayOfWeek
FUNCTION JulianDate(tdDate as Date) as Date if PARAMETERS()=0 then tdDate = date() endif return (tdDate - DATE(YEAR(tdDate)-1, 12, 31)) ENDFUNC && JulianDate