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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The date of last day in the month - VFP8 1

Status
Not open for further replies.

kmagy

MIS
Oct 21, 2003
38
JO
Hi every body

Please help me if there is any function in VFP8 that return the date of last day in the month. eg 31-Jan,2004
or 29-Feb,2004

Thanks in advance
 
Kmagy,

There is no such function in VFP, but it is easy to write it yourself:

FUNCTION LastOfMonth
nextmonth = GOMONTH(DATE(),1)
RETURN nextmonth - day(nextmonth)
ENDFUNC

You could easily extend it to accept any date as a parameter, and use that date instead of DATE().

Mike


Mike Lewis
Edinburgh, Scotland
 
this works in vfp6:

? dlast(2,2004)

FUNCTION dlast
PARAM nmonth, nyear
LOCAL ddate

ddate = CTOD(TRANSFORM(nmonth+1) + "/1/" + TRANSFORM(nyear))
RETURN ddate - 1
ENDFUNC



kilroy [trooper]
philippines
"and that's what we call creativity..."
 


This thread thread184-372056 also contained some variations that might be usefull.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
I wrote this FAQ : faq184-3683 which has a number of day of month type functions.

Hope it helps,

Stewart
 
Sir Mike,

Also, isn't it sensitive to the SET DATE setting?

Yes, i think that my code is sensitive in SET DATE settings. I guess i forgot to store the date settings first [using SET('DATE')] before doing the function and returning it back.

I think your code returns the first day of the month, not the last.

It will return the first day, I tested it. Maybe you just missed the RETURN ddate - 1 command before the ENDFUNC. [smile]

kilroy [trooper]
philippines
"and that's what we call creativity..."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top