Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginning and End of Month Functions 3

Status
Not open for further replies.

gguerra3

IS-IT--Management
Feb 1, 2006
17
US
I am needing some UDF's that will return the 1st and last day of the month for a given month.

I had some written in FP2.x but they no longer function correctly in VFP9, I think since dates are handled differently. I could rewrite them, but I thought someone may have already done this or maybe theres something already in VFP.

I need BOMONTH(). i.e. BOMONTH(2) returns '02/01/2006'
and EOMONTH() i.e. EOMONTH(2) returns '02/28/2006'

Is there something out there already??

Thanks
 
Code:
FUNCTION BOMONTH(lnMonth, lnYear)
IF VARTYPE(lnYear) $ [N]
   m.lnYear = YEAR(DATE())
ENDIF

IF VARTYPE(lnMonth) $ [N]
   m.lnYear = MONTH(DATE())
ENDIF

IF NOT BETWEEN(lnMonth, 1, 12)
  RETURN {}
ENDIF

RETURN DATE(m.lnYear, m.lnMonth, 1)



FUNCTION EOMONTH(lnMonth, lnYear)
LOCAL ldRetVal
m.ldRetVal = BOMONTH(lnMonth, lnYear)
IF EMPTY(m.ldRetVal0
   RETURN {}
ENDIF
RETURN GOMONTH(m.ldRetVal,1)-DAY(m.ldRetVal)

Borislav Borissov
 
O God,
I have 3 typos :)
In BOMONTH()
Code:
IF VARTYPE(lnMonth) $ [N]
   m.lnYear = MONTH(DATE())
ENDIF

IF VARTYPE(lnMonth) $ [N]
   m.lnYear = MONTH(DATE())
ENDIF

must be:
Code:
IF VARTYPE(lnMonth) # [N]
   m.lnYear = MONTH(DATE())
ENDIF

IF VARTYPE(lnMonth) # [N]
   m.lnYear = MONTH(DATE())
ENDIF

In EOMOTNH()
Code:
IF EMPTY(m.ldRetVal0
   RETURN {}
ENDIF

must be
Code:
IF EMPTY(m.ldRetVal)
   RETURN {}
ENDIF

Borislav Borissov
 
Oh, How do you call the functions??

I tried BOMONTH(2,2006) got an error??
 
Strange, I got a result:
Code:
? BOMONTH(2,2006)
? EOMONTH(2,2006)


FUNCTION BOMONTH(lnMonth, lnYear)
IF VARTYPE(lnYear) # [N]
   m.lnYear = YEAR(DATE())
ENDIF

IF VARTYPE(lnMonth) # [N]
   m.lnYear = MONTH(DATE())
ENDIF

IF NOT BETWEEN(lnMonth, 1, 12)
  RETURN {}
ENDIF

RETURN DATE(m.lnYear, m.lnMonth, 1)



FUNCTION EOMONTH(lnMonth, lnYear)
LOCAL ldRetVal
m.ldRetVal = BOMONTH(lnMonth, lnYear)
IF EMPTY(m.ldRetVal)
   RETURN {}
ENDIF
RETURN GOMONTH(m.ldRetVal,1)-DAY(m.ldRetVal)

Borislav Borissov
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top