Skip to Content

How to get the day count between two given dates excluding Saturday and Sunday

How to get day counts between two given dates excluding Saturday and Sunday.?

Key for the given requirement is the date variable in ABAP itself. Actually date variable in ABAP is the count of days from 01.01.0001 to given date internally.

So if we pass the date variable value to an integer variable and display it, it will display the day count for 01.01.0001 to the given date.

e.g: DATA:  lv_date  TYPE d VALUE ‘00010201’,
                  lv_count TYPE i.

            lv_count = lv_date.
            WRITE:/ lv_count.

The output is 31.

Now to how to get the day of a date?

The answer again lies in the date variable. If we get the modulus of 7 for the date variable it ‘ll give the day as

2 -> Monday
3 -> Tuesday
4 -> Wednesday
5 -> Thursday
6 -> Friday
0 -> Saturday
1 -> Sunday

E.g. DATA:  lv_date  TYPE d VALUE 20120102′,
                  lv_count TYPE i.

        lv_count = lv_date MOD 7.
         WRITE:/ lv_count.

The Output is 2 i.e 01.01.2012 is a Monday.

Now the following Function Module can be used for getting the day count excluding Saturday and Sunday.

*”*”Local Interface:
* Technical Consultant : Rakesh M Mondal
* Date                 : 06.09.2010
* Description          : Get Days Count between to dates excluding
*                        Saturday and Sunday
*Local Data declarations
   DATA: lv_date_to     TYPE endda,
         lv_total_days  TYPE i,
         lv_day_from    TYPE p,
         lv_day_to      TYPE p,
         lv_week        TYPE i,
         lv_days        TYPE i,
         lv_fw_count    TYPE i.

*~If To date is not given it ‘ll curent system date~*
   IF iv_date_to IS INITIAL.
     lv_date_to =  sy-datum.
     lv_date_to =  iv_date_to.

*Calculatin the total no of days between the given dates including the to date.
   lv_total_days =  lv_date_to – iv_date_from + 1 .

*~Determining the day of from date~*
   PERFORM get_day USING iv_date_from  CHANGING lv_day_from.

*~Determining the day of to date~*
   PERFORM get_day USING lv_date_to   CHANGING lv_day_to.

*if from date  is not a monday then
*deduct the no of days till first monday
*and calculate the Saturday and sunday for that week.

   IF lv_day_from NE 1.
     lv_days = lv_total_days – ( ( 7 – lv_day_from ) + 1 ).
     IF lv_day_from GT 6.
       ” If the day is Sunday then LV_FW_COUNT will be 1
       lv_fw_count =  1.
* if it is Monday to Satuday then the LV_FW_COUNT will be 2.
       lv_fw_count =  2.
*if From date is a Monday then just pass the total no of days between
*From date to TO DATE
     lv_days = lv_total_days.

*if the To Date is not a sunday then
*deduct the no of days till last sunday
   IF lv_day_to NE 7.
     lv_days = lv_days –   lv_day_to .
*Calculating no of weeks for the remainig days
   lv_week = lv_days / 7.

* Calculating total no of days excluding saturday and sunday
* = ( total no of day between the given intput ) –
*   ( twice of week i.e no of Saturday and Sunday ) –
*   ( Satuday and Sunday of the first week ).
   ev_no_days = lv_total_days – ( 2 * lv_week ) – lv_fw_count.


*&      Form  GET_DAY
* To get the day for the given date
* 2 -> Monday
* 3 -> Tuesday
* 4 -> Wednesday
* 5 -> Thursday
* 6 -> Friday
* 0 -> Saturday
* 1 -> Sunday
*      –>P_Date  Date
*      <–P_DAY   Day

FORM get_day USING    p_date  TYPE scdatum
              CHANGING p_day   TYPE p.
   p_day = p_date MOD 7.
   IF p_day > 1.
     p_day = p_day – 1.
     p_day = p_day + 6.
ENDFORM.                    ” GET_DAY

You must be Logged on to comment or reply to a post.
    • Hello Andrei,

      Its sample code only, I have use it for finding age of document (excluding Saturday and Sunday). The good part of this code is that it takes almost same time of execution for any set of dates.

      • Ok, I got it. But it only serves for exact purpose. I mean you calculate duration assuming that only Saturday and Sunday are weekends, right? What about holidays? Or countries where weekends are different from Saturday and Sunday? For instance, Israel has Friday and Saturday as weekends.

        Reinventing the wheel is good. No, I’m not kidding. That is real good for understanding how the system works. And your code works well. And fast. But  in general your task should be solved by FM DURATION_DETERMINE which returns duration between two days considering factory calendar.

  • Hi All,

    it will count the no of days between the given date and end date without Saturday and Sunday..thanks Rakesh…. i got same requirement.



  • Hi Rakesh,

    thank you for sharing this, but there is another quite simple and powerful function module FIMA_DAYS_BETWEEN_TWO_DATES which can handle your requirements and has some interesting options.


    • Factory Calendar / or not
    • Include specific times
    • different counting methods, if you want to do some financial calculations
    • Leap-Year handling. BTW: I am not quite sure, If your code does a correct leap year handling.

    Kind regards,


    • Hi Hendrik,

      Thanks for the input.Yes it can handle leap year correctly. Here you should look at the interesting fact of the Date variable in ABAP.