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: 

saturday's between date range

Former Member
0 Kudos

Hi All,

I need to findout the number of satuday's between the given date range.

Please tell me if there are any function modules or methods to calculate this.

Regards

Suprith

7 REPLIES 7

Former Member
0 Kudos

Iterate the date range (from date - to_date) with the function module "DATE_TO_DAY", add counter if function module returns 'Satruday'

Regards

Former Member
0 Kudos

Hello

Try this snippet:


data: begdat type sydatum,
     enddat type sydatum,
     day type p,
     counter type i.
begdat = '20100401'. "<- start date here
enddat = '20100430'. "<- end date here
do.
  day = begdat mod 7.
  if day > 1.
     day = day - 1.
  else.
     day = day + 6.
  endif.
  if day = '6'. "<- saturday
    counter = counter + 1.
  endif.
  if begdat < enddat.
    begdat = begdat + 1.
  else.
    exit.
  endif.
enddo.
write: counter.

Former Member
0 Kudos

there are a LOT of FM´s you could use on the track.

at first i would look what day your first day of your range is. Therefor use FM "DATE_TO_DAY".

Then i would calculate how much days from your range start it is to the first saturday.

Assuming todays date, this makes: Saturday - Thursday = 2.

Now calculate the number of days in your range. do that by subtracting range start date from range end date.

subtract the number of days to first saturday from this.

Now divide by 7 without rest (use statement "DIV" for that.

Now you got the number of saturdays in your range.

GauthamV
Active Contributor
0 Kudos

Basic date posts are not permitted.

Former Member
0 Kudos

Hi Suprith,

Please refer the below Code.


CALL FUNCTION 'DAY_ATTRIBUTES_GET'
 EXPORTING
*   FACTORY_CALENDAR                 = ' '
*   HOLIDAY_CALENDAR                 = ' '
   DATE_FROM                        = From_Date
   DATE_TO                          = To_Date
   LANGUAGE                         = SY-LANGU
*   NON_ISO                          = ' '
* IMPORTING
*   YEAR_OF_VALID_FROM               =
*   YEAR_OF_VALID_TO                 =
*   RETURNCODE                       =
  TABLES
    day_attributes                   = it_day_attri
* EXCEPTIONS
*   FACTORY_CALENDAR_NOT_FOUND       = 1
*   HOLIDAY_CALENDAR_NOT_FOUND       = 2
*   DATE_HAS_INVALID_FORMAT          = 3
*   DATE_INCONSISTENCY               = 4
*   OTHERS                           = 5
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

in the Export internal table it_day_attri you will get all the dates and its respective days. if you delete the records other than Saturday , the number of entries will be needed count of saturday.

delete it_day_attri where WEEKDAY  <> '6'.

DESCRIBE TABLE it_day_attri LINES Count. 

note : weekday day number ( Saturday = 6 may vary based on factory calendar )

Edited by: Prasath Arivazhagan on Apr 8, 2010 1:07 PM

franois_henrotte
Active Contributor
0 Kudos
DATA: w_weeks TYPE p DECIMALS 1,
      w_sat   TYPE i,
      w_day_p TYPE p.

PARAMETERS: p_date1 TYPE begda,
            p_date2 TYPE endda.

START-OF-SELECTION.

  w_weeks = ( p_date2 - p_date1 ) / 7.
  w_sat = floor( w_weeks ).

  w_day_p = p_date1 MOD 7.
  IF w_day_p = 0.
    w_sat = w_sat + 1.
  ENDIF.

  WRITE: / w_sat, 'saturdays between', p_date1, 'and', p_date2.

Former Member
0 Kudos

Moderator message - Please see before posting. Date questions are generally not allowed. - post locked Rob