Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: FoxPro FAQ

Usefull Functions & Procedures

Return the first or last day of the month by StewartUK
Posted: 4 Jun 03

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
 GOMONTH(GOMONTH(myDate, IIF(DAY(mydate)=1,1,0)) - DAY(GOMONTH(myDate, IIF(DAY(mydate)=1,1,0))-1),-1)
For the last day of the previous month
 GOMONTH(myDate, 0) - DAY(GOMONTH(myDate, 0))

For the first day of the current month
 GOMONTH(myDate, IIF(DAY(mydate)=1,1,0)) - DAY(GOMONTH(myDate, IIF(DAY(mydate)=1,1,0))-1)
For the last day of the current month
 GOMONTH(myDate, 1) - DAY(GOMONTH(myDate, 1))

For the first day of the next month
 GOMONTH(GOMONTH(myDate, IIF(DAY(mydate)=1,1,0)) - DAY(GOMONTH(myDate, IIF(DAY(mydate)=1,1,0))-1),1)
For the last day of the next month

Back to Microsoft: FoxPro FAQ Index
Back to Microsoft: FoxPro Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close