How to get difference in days between 2 dates excluding weekends

Hi all,
i have a requirement, to calculate the difference between 2 dates, in days.
eg: 01/08/2007 and 05/08/2007.
     Difference = 4 days.
But here my actual requirement is i have to calculate this difference excluding weekends (saturday n sundays).
eg: 01/08/2007 -
Thursday
     05/08/2007 -
Monday
so now Difference = 2 days.
Please help me regarding this.
Points will be rewarded for helpfull answers.
Thanks in Advance.
Regards,
Vineel

see these codes of rich
report zrich_0003.
data: begin of itab occurs 0,
      datum type sy-datum,
      end of itab.
data: weekday like dtresr-weekday.
data: number_lines type i.
parameters: p_sdatum type sy-datum,
            p_edatum type sy-datum.
itab-datum = p_sdatum.
append itab.
do.
  if itab-datum = p_edatum.
    exit.
  endif.
  itab-datum = itab-datum + 1.
  call function 'DATE_TO_DAY'
       exporting
            date    = itab-datum
       importing
            weekday = weekday.
  if weekday = 'Sat.'
    or weekday = 'Sunday'.
    continue.
  endif.
  append itab.
enddo.
describe table itab lines number_lines.
write:/ 'Number of days between dates is', number_lines.
and
report zrich_0001.
parameters: p_start type sy-datum,
            p_end   type sy-datum.
data: idays type table of   rke_dat with header line.
data: workingdays type i.
call function 'RKE_SELECT_FACTDAYS_FOR_PERIOD'
     exporting
          i_datab               = p_start
          i_datbi               = p_end
          i_factid              = 'P8'  " Fact Calender ID
     tables
          eth_dats              = idays
     exceptions
          date_conversion_error = 1
          others                = 2.
describe table idays lines workingdays.
write:/ workingdays.
I want to find the No.of working days between the two dates
regards,
srinivas

Similar Messages

  • How to get diff of days between 2 dates

    Hi,
    I have a given date . I am looking for a simple way to get the difference of days between the 2 date like :
    currentDay - givenDate Day > 20 .
    I am using calendar for this. MyCode:
    java.util.Calendar calendar1 = Calendar.getInstance();
    calendar1.set(2003, 08,16);
    int userCreatedDay = calendar1.get(Calendar.DAY_OF_YEAR);
    java.util.Calendar calendar2 = Calendar.getInstance();
    int currDay = calendar2.get(java.util.Calendar.DAY_OF_MONTH);
    int currYear = calendar2.get(java.util.Calendar.YEAR);
    int currMonth = calendar2.get(java.util.Calendar.MONTH);
    int days= currDay - userCreatedDay;
    System.out.println("currDay:"+currDay+",createDay:"+userCreatedDay);
    System.out.println("Days left:"+currDay - userCreatedDay);
    if(days > 14) return true;
    o/P:
    currDay:266,createDay:249
    Days left : 17
    If i calculate today diff of days in only 7. I am not able to understand why the result is being displayed as 17.
    Is there anything wrong i am uisng this class.
    Please, help

    Personally, I do not like using the calendar class for this sort of thing. Why? Weel lets look at two simple dates: 4th of July 1777 and 21st March 2003.
    So I would create 2 GregorianCalendar objectsGregorianCalendar independenceDay = new GregorianCalendar (1777, 6, 4);
    GregorianCalendar startOfIraqWar  = new GregorianCalendar (2003, 2, 12);Now what do these contain? Well, here is the output (cut down for clarity)...
    independenceDay = [time=?, YEAR=1777,MONTH=6,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,
                       DAY_OF_MONTH=4,DAY_OF_YEAR=?,DAY_OF_WEEK=?,
                       DAY_OF_WEEK_IN_MONTH=?]
    startOfIraqWar = [time=?, YEAR=2003,MONTH=2,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,
                       DAY_OF_MONTH=12,DAY_OF_YEAR=?,DAY_OF_WEEK=?,
                       DAY_OF_WEEK_IN_MONTH=?]
    So what don't I like? All the useful fields are not filled in. They ***could*** be calculated by the constructor, but they aren't, particularly things like DAY_OF_YEAR, which would ease calculation enormously.
    What I would really like to see in GregorianCalendar is a diff() method which takes a GregorianCalendar as its argument and returns a time difference. In fact, you may want several, or an additional argument daying how you want the diff returned (days, years, seconds).

  • Confused - How to Calculate Number of Days Between Dates but Exclude Weekend Dates If There Hasn't Been a Weekend Update

    Hello -
    I've been tearing my hair out over this problem i'm trying to solve, probably just been staring at it too long which is making it worse -
    I have a series of open support tickets which are supposed to be updated on a daily basis, the problem is that they aren't always being updated daily.  So, the business wants to know the number of days from when a ticket was last updated and today's
    date.  I have this basic calculation and it's working fine, however now the business wants to exclude weekends from the calculation.  The other problem is that some reps DO go in on weekends and update their tickets, so sometimes there will be updates
    made on weekend dates.
    To give an example -
    Today's date is 2014-02-10 (Monday).  A ticket was last updated last Thursday, 2014-01-30.  The difference between the two dates is 11, so it's been 11 days since the ticket was last updated.  Now, if I exclude Saturdays and Sundays, then
    it's actually been 7 days since the ticket was last updated.  I'm not sure how to do this in T-SQL.
    Now, to further complicate the problem, sometimes a ticket IS updated on a Saturday or Sunday.  So, if a ticket was updated on 2014-02-02 (Sunday), then it should be counted.  Again i'm not sure how to do this. 
    What gets me is that this is probably fairly simple and i've just been staring at it too long.  In the meantime, can someone offer some guidance?
    Thanks!!

    I've adapted this from a function on my blog. you will need to add set the YourTicketTable to where ever your tickets are stored.
    CREATE
    FUNCTION [dbo].[CalcWorkDaysBetween](@StartDate
    As DateTime,@EndDate
    AS DateTime)
    RETURNS
    INT AS
    BEGIN
    SET @EndDate
    =DATEADD(DAY,1,@EndDate)
    DECLARE @Count
    AS Int= 0
    DECLARE @Date
    As Date=@StartDate
    WHILE @Date
    < @EndDate
    BEGIN
    IF (DATEPART(WEEKDAY,@Date)IN(1,7)
    OR (SELECT
    Count(*)
    FROM YourTicketTable WHERE TicketDate=@Date)=1)
    BEGIN
    SELECT @Count = @Count
    + 1
    END
    SELECT @Date=DATEADD(Day,
    1,@Date)
    END
    RETURN
    DATEDIFF(DAY,@StartDate,@EndDate)- @Count
    END
    Regards,

  • Time between dates excluding Weekends and Holidays

    I am fairly new to Power Pivot and I am having trouble with this formula.  I need my Cycle Time Days column to capture the days between CreatedDataTime and ClosedDateTime excluding Weekends and Holidays.  I have a tab that has the holidays but
    I can't get the formula correctly?   Jill
    CreatdDateTime        ClosedDateTime     Cycle Time Days
    12/1/2014                    12/10/2014

    first of all you need a separate time table which holds all possible dates for your model
    there should be no gaps, it should contain full years and a column of datatype DateTime as unique key
    once you have this in place add a calculated column to this table as 
    =IF(INT(FORMAT([Date], "w")) >= 6, "Weekend", "Workday")
    then go back to your original table and add the following calculation for your [Cycle Time Days]-column:
    =COUNTROWS(
    FILTER(
        'Dates',
        Dates[Date] >= DateRanges[DateFrom]
        && Dates[Date] <= DateRanges[DateTo]
        && 'Dates'[IsWeekend] = "Workday"
    Holidays are a bit more tricky but you can follow the same pattern but you need to get the holidays from somewhere
    hth,
    -gerhard
    Gerhard Brueckl
    blogging @ http://blog.gbrueckl.at
    working @ http://www.pmOne.com

  • How can get difference between 2 dates in the form of days

    how can get difference between 2 dates in the form of days

    Hi,
    Check the following program:
    REPORT ZDATEDIFF.
    DATA: EDAYS   LIKE VTBBEWE-ATAGE,
          EMONTHS LIKE VTBBEWE-ATAGE,
          EYEARS  LIKE VTBBEWE-ATAGE.
    PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,
                TODATE   LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.
    call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
      exporting
        i_date_from          = FROMDATE
        i_date_to            = TODATE
      I_FLG_SEPARATE       = ' '
      IMPORTING
        E_DAYS               = EDAYS
        E_MONTHS             = EMONTHS
        E_YEARS              = EYEARS.
    WRITE:/ 'Difference in Days   ', EDAYS.
    WRITE:/ 'Difference in Months ', EMONTHS.
    WRITE:/ 'Difference in Years  ', EYEARS.
    INITIALIZATION.
    FROMDATE = SY-DATUM - 60.
    Regards,
    Bhaskar

  • How can i get number of days between two dates represented by two dates?

    how can i get number of days between two dates represented by two date objects. One is java.sql.Date, the other is java.util.Date?

    tej_222 wrote:
    But how do I do that conversion. from java.sql.date and java.util.date to calender?
    -thanks for the quick response.You may find the following utility code samples useful:
    [http://balusc.blogspot.com/2007/09/calendarutil.html]
    [http://balusc.blogspot.com/2007/09/dateutil.html]
    ganeshmb wrote:
    (date1.getTime() - date2.getTime())/(1000*60*60*24) should do.
    getTime returns millsecond value of date object and the difference divided by no of milliseconds in a day should fetch you the difference in terms of days.This doesn't respect the DST. Use java.util.Calendar.

  • How do i get number of days between 2 dates?

    How do i get number of days between 2 dates?
    and the result must be in int.
    for example
    Ex. startdate: 2006-06-01 enddate: 2006-06-30 and the result is: 30
    how to do so? thx

    mel
    Iv'e used this method. It assumes startdate,enddate and days have been defined before but you could pass them as args.
    void days()
        try
          Date d1 = DateFormat.getDateInstance().parse(startdate);
          Date d2 = DateFormat.getDateInstance().parse(enddate);
          long days = (d2.getTime()-d1.getTime())/1000/60/60/24;
          days = ""+days;
        catch (ParseException e)
          System.out.println("Invalid date format");
      }It actually gets the duration in ms and divides down to days.
    Regards
    Chris

  • How  can I get number of days between 2 dates ?

    How can I get number of days between 2 dates ?
    Give me answer as soon as possible.....

    Mukesh_Prajapat wrote:
    How can I get number of days between 2 dates ?
    Give me answer as soon as possible.....Is google broken again?
    [How To Ask Questions The Smart Way|http://www.catb.org/~esr/faqs/smart-questions.html]

  • Calculate Difference in Days Between two Dates

    Hi,
    I'm trying to figure out how to calculate the difference in days between two dates using JavaScript in LiveCycle. (JavaScript knowledge = minimal)
    Where "Start_Date" and "Current_Date" are the names of the two dates in the Hierarchy palette. (both Date/Time Field)
    *Current date is using the Object > Value > Runtime Property > Current Date/Time
    I need a Text or Numeric field displaying the difference in days. (Difference_in_Days)
    I've noticed the following code being pretty standard amongst other responses:
    var 
    Start_Date = new Date(Start_Date);
    var 
    Current_Date = new Date(Current_Date);
    var 
    nAgeMilliseconds = Current_Date.getTime() - Start_Date.getTime();
    var 
    nMilliSecondsPerYear = 365 * 24 * 60 * 60 * 1000;
    I know there's code missing, and the above code might not be correct.
    Please advise.

    Where "DateField01" = user entered date field
    Where "DateFiled02" = Current Date/Time (Runtime Property)
    where "Subform" = the subform containing DateField01
    My script now resembles:
    var oneDay = 24*60*60*1000;
    var firstDate = new Date(Subform.DateField01.rawValue);
    var secondDate = new Date(DateField02.rawValue);  
    (firstDate.getTime() - secondDate.getTime()) / oneDay;
    I tried adding:
    app.alert(String(diffDays));
    Although I assume the reason I didn't get an error is because DateField01 is empty when the form is opened.
    If I swap in actual dates instead of fields it works perfectly.
    When I use the fields I have no information populating after I enter a date in "DateField01"

  • How to get the first day in the month from a domain date ?

    Hi,
    I like to know how to get the first day in the month from a domain date?
    Thanks
    Stephen

    Hi Gokul...
    Instead of using the funtion module you can just write the 3 statements of code to get the first day of the week.
    Its similar to the above one but instead of writing case statement you can achive the following.
    data : w_res type i,
             w_data type d,
    w_res = w_date mod 7.
    w_date = w_date - w_res.
    write w_date.
    This works.
    Regards,
    Siddarth

  • How to get the exact day date with the another date field?

    Hi,
    Please help me how to get the specific day of the week's date with the help of another date field.
    Actually , one field(week_day) has 1,2,3,4,5,6,7 here 1--MON,2-- TUE like that.
    another field has the date. based on that date, we have to go to that particular week and need to pick up the date by the above week_day. It should be in that week itself.
    Thanks in advance!!
    Regards,
    Vissu...
    Edited by: vissu on Oct 29, 2010 3:07 AM

    Hi,
    Something like this
    SELECT TRUNC(<DATE_COLUMN>,'DAY')+<WEEK_NO_COLUMN> FROM <YOUR_TABLE>;for the particular week of the date
    SELECT TRUNC(SYSDATE,'DAY')+<WEEK_NO_COLUMN> FROM <YOUR_TABLE>;for the current week
    cheers
    VT

  • How to count the days between Date Range using OO ABAP?

    hi experts,
            i want to count the days between Date Range using OO ABAP for that  which class and method  can i use?.
    Thanks,
    Mahesh.

    Not sure I understand the requirement for it to be OO, but you could always write your own (i.e. use this):
    REPORT zz_date_diff.
    CLASS date_diff DEFINITION.
      PUBLIC SECTION.
        METHODS diff IMPORTING     i_date_fm TYPE d
                                   i_date_to TYPE d
                     EXPORTING     e_days    TYPE i.
    ENDCLASS."
    CLASS date_diff IMPLEMENTATION.
      METHOD diff.
        e_days = i_date_to - i_date_fm.
      ENDMETHOD."
    ENDCLASS."
    DATA: g_ref TYPE REF TO date_diff,
          g_days  TYPE i,
          g_date_fm  TYPE d VALUE '20080101',
          g_date_to  TYPE d VALUE '20090101'.
    START-OF-SELECTION.
      CREATE OBJECT g_ref.
      CALL METHOD g_ref->diff
        EXPORTING
          i_date_fm = g_date_fm
          i_date_to = g_date_to
        IMPORTING
          e_days    = g_days.
      WRITE g_days.

  • How to get the last day of the week?

    Hii
    i can get the calender week number for any given date using
    SELECT to_char(to_date('04/04/2011','MM/DD/YYYY'),'WW') FROM dual
    can any body tell me, how to get the last day of that week ?
    and the answer should be 04/08/2011(8th april )
    thanks
    San
    Edited by: sandeep9 on Apr 4, 2011 3:50 AM

    Hi, San,
    Here's one way:
    WITH     sample_data     AS
         SELECT  DATE '2011-04-04'     AS dt
         FROM     dual
    SELECT  dt
    ,     TO_CHAR (dt, 'WW')     AS week_num
    ,     NEXT_DAY ( dt - 1
               , TO_CHAR ( TRUNC (dt, 'YEAR') - 1
                      , 'Day'
               )          AS end_o_week
    FROM     sample_data;Another way is to use date arrithmetic:
    WITH     sample_data     AS
         SELECT  DATE '2011-04-09'     AS dt
         FROM     dual
    SELECT  dt
    ,     TO_CHAR (dt, 'WW')     AS week_num
    ,     TRUNC (dt, 'YEAR')
          + (7 * CEIL ( (dt - (TRUNC (dt, 'YEAR') - 1))
                / 7
          - 1               AS using_date_arithmetic
    FROM     sample_data;

  • How to get the last day of a month?

    HI,
    I want to know how to get the last day of a month.
    In my JClient form, I tried to get it by using oracle.sql.Date method, that is:
    lastday=oracle.sql.Date anydate.lastDayOfMonth();
    But it does not work. The result is lastday=anydate.
    Why?
    Stephen

    You can use the Calender class...
    Calendar c = Calendar.getInstance();
    and then something like...
    c.add(c.MONTH, 1);
    int dayOfMonth = c.get(Calender.MONTH);
    c.add(c.DAY_OF_MONTH, - (dayOfMonth-1) );
    other usefull functions are:
    System.out.println(" YEAR : " + c.get(Calendar.YEAR));
    System.out.println(" MONTH : " + c.get(Calendar.MONTH));
    System.out.println(" DAY_OF_MONTH : " + c.get(Calendar.DAY_OF_MONTH));
    System.out.println(" DAY_OF_WEEK : " + c.get(Calendar.DAY_OF_WEEK));
    System.out.println(" DAY_OF_YEAR : " + c.get(Calendar.DAY_OF_YEAR));
    System.out.println(" WEEK_OF_YEAR : " + c.get(Calendar.WEEK_OF_YEAR));
    System.out.println(" WEEK_OF_MONTH : " + c.get(Calendar.WEEK_OF_MONTH));
    System.out.println(" DAY_OF_WEEK_IN_MONTH : " + c.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println(" HOUR : " + c.get(Calendar.HOUR));
    System.out.println(" AM_PM : " + c.get(Calendar.AM_PM));
    System.out.println(" HOUR_OF_DAY (24-hour): " + c.get(Calendar.HOUR_OF_DAY));
    System.out.println(" MINUTE : " + c.get(Calendar.MINUTE));
    System.out.println(" SECOND : " + c.get(Calendar.SECOND));
    System.out.println();*/

  • How to get the last day according to fiscal period input in selection scree

    Hello expert
    how to get the last day of fiscal period input.
    the fiscal period inculdes 1-16
    when fiscal period is greater than 12, only calculate the last day of 12nd month
    your solution will be apprecaited, FM existing?
    thank you
    Kevin

    Hi,
    when you give a particular date in any month
    the following fm will give you the last date of that month
    here you can give
    R_FDATE-HIGH  as 01 and month as the period you wnat and year for current year
    concatenates '01'  month year  into r_fdate-high separated by '.'.
    then it will give g_ltdt for that month and year which wil be the last date of that month
        CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
          EXPORTING
            DAY_IN            = R_FDATE-HIGH
          IMPORTING
            LAST_DAY_OF_MONTH = G_LTDT
          EXCEPTIONS
            DAY_IN_NO_DATE    = 1
            OTHERS            = 2.
        IF SY-SUBRC <> 0.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
    thanks & regards,
    Venkatesh

Maybe you are looking for

  • Unable to load CS4 to new iMac

    I purchased CS4 from Adobe a few days ago and followed the instructions to load to a new iMac (OS 10.5 4GB Ram) which is a couple of weeks old. This is the first software I have attempted to load onto it.  After trying twice and getting an error mess

  • Error while using UTL_FILE

    I am getting the following error while using UTL_FILE procedure while using UTL_FILE.FOPEN procedure from system account. I am using Windows XP with NTFS. SQL> create or replace directory FILE_DIR as 'C:\' 2 / Directory created. SQL> grant read on di

  • Objects in a tablespace or datafile ???

    How do we find out what objects ( tables, indexes etc ) are there in a particular tablespace ? Is there a way to find which object is in a particular datafile if the tablespace has more than one datafile ?

  • Adobe 5.0 vs Vista - ARGH!

    Hello, all, I'm hoping someone will be able to help me. I've got Adobe Acrobat 5.0 (full version) installed on my laptop which is running Vista. I can view documents, but not convert files to PDF. I've read a few forums that have told me to upgrade,

  • Java.sql.SQLException: Cannot call rollback when using distributed transac

    Hi all, I am getting the below exception trace when I tried to rollback the data in WLI.I am getting the db connection Object from DBControl. java.sql.SQLException: Cannot call rollback when using distributed transactions at weblogic.jdbc.wrapper.JTA