Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
** simple functions for WeekOfMonth
** This bit helps you test it!
clear
set date british
m.date = date()
do while lastkey() <> 27
@ 10,10 say "Date" get m.date
read
clear gets
@ 11,10 say FirstDay(m.date)
@ 12,10 say NextSunDay(FirstDay(m.date))
@ 13,10 say WeekOfMonth(m.date)
enddo
** this is the actual function
function WeekOfMonth
parameter m.date
private m.date,i
** 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
** 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 two days - because
** the first week has been excluded by the if, and we want the
** balance to start at 2
i = int((Day(m.date)-i)/7)+2
else
i = 1
endif
return(i)
** this always gives you the first day of any month
function FirstDay
parameter m.date
private m.date
m.date = ctod("01/"+alltrim(str(month(m.date)))+"/"+alltrim(str(year(m.date))))
return(m.date)
** 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
endif
return(m.date)
** simple functions for WeekOfMonth
** This bit helps you test it!
clear
set date british
m.date = date()
do while lastkey() <> 27
@ 10,10 say "Date" get m.date
read
clear gets
@ 11,10 say FirstDay(m.date)
@ 12,10 say NextSunDay(FirstDay(m.date))
@ 13,10 say WeekOfMonth(m.date)
enddo
** 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
else
m.factor = 1
endif
** 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
else
i = 1
endif
return(i)
** this always gives you the first day of any month
function FirstDay
parameter m.date
private m.date
m.date = ctod("01/"+alltrim(str(month(m.date)))+"/"+alltrim(str(year(m.date))))
return(m.date)
** 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
endif
return(m.date)