This was developed from thread184-566780 with thanks to Andrew Coates for the syntax for the last day of the month.
Obviously myDate is a variable of type DATE. You could replace this with the VFP DATE() for the current date.
You could easily put these into a function feeding in mydate and constants (say 1 to get the first day & 31 to get the last day) to determine whether the function returns the first day of the month or the last day. You could have a third parameter for stating whether to return dates for the previous, current or next month say -1, 0 & 1.
I've tested these functions with first, middle & last dates of the next 12 months (which includes a leap-year) and they seemed to return the correct results in every case.
For the first day of the previous month
[color blue]GOMONTH(GOMONTH(myDate, IIF(DAY(mydate)=1,1,0)) - DAY(GOMONTH(myDate, IIF(DAY(mydate)=1,1,0))-1),-1)[/color]
For the last day of the previous month
[color blue]GOMONTH(myDate, 0) - DAY(GOMONTH(myDate, 0))[/color]
For the first day of the current month
[color blue]GOMONTH(myDate, IIF(DAY(mydate)=1,1,0)) - DAY(GOMONTH(myDate, IIF(DAY(mydate)=1,1,0))-1)[/color]
For the last day of the current month
[color blue]GOMONTH(myDate, 1) - DAY(GOMONTH(myDate, 1))[/color]
For the first day of the next month
[color blue]GOMONTH(GOMONTH(myDate, IIF(DAY(mydate)=1,1,0)) - DAY(GOMONTH(myDate, IIF(DAY(mydate)=1,1,0))-1),1)[/color]
For the last day of the next month
[color blue]GOMONTH(mydate,2)-DAY(GOMONTH(mydate,2))[/color]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.