Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Function for counting a sunday in a particular month

Former Member
0 Kudos

Dear all,

i have a date like 01.10.2008 & 31.10.2008.

now i want to count the number of sundays arrived in between this month.

Have any function???????????

plz help me.

Anshuman

1 ACCEPTED SOLUTION

Former Member
0 Kudos

try using this code

data: begdat type sydatum,
     enddat type sydatum,
     day type p,
     counter type i.
begdat = '20081001'.
enddat = '20081031'.
do.
  day = begdat mod 7.
  if day > 1.
     day = day - 1.
  else.
     day = day + 6.
  endif.
  if day = '6'.
    counter = counter + 1.
  endif.
  if begdat < enddat.
    begdat = begdat + 1.
  else.
    exit.
  endif.
enddo.
write: counter,'SUNDAYS'.

5 REPLIES 5

Former Member
0 Kudos

try using this code

data: begdat type sydatum,
     enddat type sydatum,
     day type p,
     counter type i.
begdat = '20081001'.
enddat = '20081031'.
do.
  day = begdat mod 7.
  if day > 1.
     day = day - 1.
  else.
     day = day + 6.
  endif.
  if day = '6'.
    counter = counter + 1.
  endif.
  if begdat < enddat.
    begdat = begdat + 1.
  else.
    exit.
  endif.
enddo.
write: counter,'SUNDAYS'.

0 Kudos

Thanx a lot,

ur code solved my problem.

Bye

0 Kudos

Hi,

Plz. check ur code with 01/03/2007 and 31/03/2007

result comming incorrect

Former Member
0 Kudos

use this

HR_IE_NUM_PRSI_WEEKS to get the number of weeks between two given dates.

from this output derive the sunday.

If we have 2 weeks there will be 2 sundays right.

Try this..................

Regards,

Midhun Abraham

Edited by: Midhun Abraham on Oct 11, 2008 10:48 AM

Former Member
0 Kudos

Still result comming wrongly