Lots of spare time today so some hopefully constructive criticism: :)
I would redo some of that code to get away from CTOD() as that will fail
depending on SET STRICTDATE and if SET DATE is anything besides MDY.
I have a feeling that your first day of week and last day of week will
be incorrect in situations with SET FDOW.
I think PARAMETERS() is also advised against and PCOUNT() is better.
I would also move each function into its own program.
For example FirstDayOfQuarter.prg would be:
LPARAMETERS tdDate
LOCAL lnMonth as Integer, lnYear as Integer, ldDate as Date
if PCOUNT()=0 then
m.tdDate = date()
endif
m.lnYear = YEAR(m.tdDate)
m.lnMonth = MONTH(m.tdDate)
DO CASE
CASE BETWEEN(m.lnMonth,1,3)
m.ldDate = DATE(m.lnYear, 1, 1)
CASE BETWEEN(m.lnMonth,4,6)
m.ldDate = DATE(m.lnYear, 4, 1)
CASE BETWEEN(m.lnMonth,7,9)
m.ldDate = DATE(m.lnYear, 7, 1)
OTHERWISE && CASE BETWEEN(m.lnMonth,10,12)
m.ldDate = DATE(m.lnYear, 10, 1)
ENDCASE
return ldDate
Frank.
Frank Cazabon
On 18/05/2018 11:30 AM, mbsoftwaresoluti...@mbsoftwaresolutions.com wrote:
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
[excessive quoting removed by server]
_______________________________________________
Post Messages to: ProFox@leafe.com
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/571b0a25-bbec-a50c-2330-e6577bffc...@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.