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

Week Of Month, First Day & NextSunday functions by GriffMG
Posted: 21 Nov 03 (Edited 21 Nov 03)

** simple functions for WeekOfMonth
** This bit helps you test it!

set date british
m.date = date()
do while lastkey() <> 27
    @ 10,10 say "Date" get m.date
    clear gets
    @ 11,10 say FirstDay(m.date)
    @ 12,10 say NextSunDay(FirstDay(m.date))
    @ 13,10 say WeekOfMonth(m.date)

** this is the actual function
function WeekOfMonth
    parameter m.date
    private m.date,i,m.factor
    ** the week is...
    ** first get the day of the first sunday in the month
    ** by getting the first day, and then getting the next Sunday
    ** after that
    i = Day(NextSunDay(FirstDay(m.date)))
    ** if the day isn't before that first sunday....
    if Day(m.date) > i
        if i > 1
            m.factor = 2
            m.factor = 1
        ** calculate the differnce between the days (of your date and the
        ** first sunday) divide that by the number of days in a week
        ** (taking just the integer bit) and add the week factor - because
        ** the first week has been excluded by the if, and we want the
        ** balance to start at 2 for weeks after that
        i = int((Day(m.date)-i)/7)+m.factor
        i = 1

** this always gives you the first day of any month
function FirstDay
    parameter m.date
    private m.date
    m.date = m.date - Day(m.date) + 1
** this returns the next Sunday...    
function NextSunDay
    parameter m.date
    private m.date,i
    i = 8 - dow(m.date)  && 1=Sunday
    if i < 7
        m.date = m.date + i

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