This FirstDayOfQuarter and siblings is much easier to do:
*******************************************
FUNCTION GoQuarter(dDate, cValue)
* "L" = (L)ast day of dDate's Quarter
* "F" = (F)irst day of dDate's Quarter
* "N" = first day of (n)ext dDate's Quarter
* "P" = first day of (p)previous dDate's Quarter
*******************************************
cValue = EVL(cValue, "F")
LOCAL dResult
DO CASE
CASE cValue = "L"
dResult =
GOMONTH(dDate,(CEILING(MONTH(dDate)/3)*3)-MONTH(dDate)+1)-DAY(dDate)
CASE cValue = "F"
dResult =
GOMONTH(dDate,(CEILING(MONTH(dDate)/3)*3)-MONTH(dDate)-2)-DAY(dDate)+1
CASE cValue = "N"
dResult =
GOMONTH(dDate,(CEILING(MONTH(dDate)/3)*3)-MONTH(dDate)+1)-DAY(dDate)+1
CASE cValue = "P"
dResult =
GOMONTH(dDate,(CEILING(MONTH(dDate)/3)*3)-MONTH(dDate)-5)-DAY(dDate)+1
ENDCASE
RETURN dResult
wOOdy
"*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`.Visual FoxPro: It's magic !
(¸.·``··*
-----Ursprüngliche Nachricht-----
Von: ProFox <[email protected]> Im Auftrag von Frank Cazabon
Gesendet: Freitag, 18. Mai 2018 18:41
An: [email protected]
Betreff: Re: Fun with date calculations in VFP
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.
_______________________________________________
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/[email protected]
** 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.