Calculate the date interval in days

Hi all!
I need your kind help.
I have an oracle sql table.
here is goes..
TABLENAME: RACE
DATE NAME
11-JAN-12 JAMES
12-JAN-12 JAMES
14-JAN-12 JAMES
17-JAN-12 JAMES
22-JAN-12 JAMES
01-FEB-12 JOHN
11-FEB-12 JOHN
13-FEB-12 JOHN
14-FEB-12 JOHN
28-FEB-12 JOHN
01-MAR-12 JOHN
HOW DO I Calculate the total date interval(difference) for James and John in days?
for example in this case the total is 7 days for James(11-JAN-12 to 12-JAN-12 is 0 days and 12-JAN-12 to 14-JAN-12 is 1 day and 14-JAN-12 to 17-JAN-12 is 2 days) and 24 days for John
The data for the date will be random and can be up to 60 difference dates and names so I will like to calculate for all different names.. Thanks!

Can you explain in more detail why James should have 7 days?
Difference in dates can be easily calculated (if you use the DATE datatype, that is) by simply subtracting them.
Example:
SQL> -- generating sample data:
SQL> with race as (
  2  select to_date('11-JAN-12', 'dd-mon-yy') dt, 'JAMES' nm from dual union
  3  select to_date('12-JAN-12', 'dd-mon-yy'), 'JAMES' from dual union
  4  select to_date('14-JAN-12', 'dd-mon-yy'), 'JAMES' from dual union
  5  select to_date('17-JAN-12', 'dd-mon-yy'), 'JAMES' from dual union
  6  select to_date('22-JAN-12', 'dd-mon-yy'), 'JAMES' from dual union
  7  select to_date('01-FEB-12', 'dd-mon-yy'), 'JOHN' from dual union
  8  select to_date('11-FEB-12', 'dd-mon-yy'), 'JOHN' from dual union
  9  select to_date('13-FEB-12', 'dd-mon-yy'), 'JOHN' from dual union
10  select to_date('14-FEB-12', 'dd-mon-yy'), 'JOHN' from dual union
11  select to_date('28-FEB-12', 'dd-mon-yy'), 'JOHN' from dual union
12  select to_date('01-MAR-12', 'dd-mon-yy'), 'JOHN' from dual
13  )
14  --
15  -- actual query:
16  --
17  select max(dt)-min(dt) diff
18  ,      nm
19  from   race
20  group by nm;
      DIFF NM
        29 JOHN
        11 JAMESHowever, that is not your desired resultset. We (at least: I) need a bit more explanation why James should have 7 as date difference...
Also: DATE and NAME ar not suitable as column names.

Similar Messages

  • Using Numbers, can I calculate the date that will be eg 45 days ahead of a given date?

    Using Numbers, can I calculate the date that will be eg 45 days ahead of a given date?

    MWB,
    Certainly. Let's say that your given date is in B2. The date 45 days earlier can be found with:
    =B2 – 45.
    Almost seems too simple.
    Jerry

  • "D2008178" - FM to calculate the date of the x day in a year

    Hi all!
    I am looking for a FM to calculate the date of a certain day in the year.
    For example which date has the day 178 of the year.
    This has nothing to do with the factory calendar!!!
    Thanks a lot for your help
    CU
    Peter

    Hi Peter,
    Please check this funtion module "FIMA_DATE_CREATE".
    Sample code as follows:
    REPORT  ztest_vinay.
    DATA: w_date TYPE vtbbewe-dvalut.
    PARAMETERS: p_date TYPE vtbbewe-dvalut.
    CALL FUNCTION 'FIMA_DATE_CREATE'
      EXPORTING
        i_date                        = p_date  " Here you need to pass first day of the year
        i_calendar_days         = 178
    IMPORTING
        e_date                        = w_date.
    WRITE: w_date.
    Regards,
    Vinay
    Edited by: Vinay Kumar Amruth on Feb 18, 2009 2:52 PM
    Edited by: Vinay Kumar Amruth on Feb 18, 2009 3:01 PM

  • How can I calculate the maximum number of days between two dates in a range of dates?

    I have a column of dates spanning the couse of a few months.  I would like to know if I can calculate the maximum number of days between each row and display the highest number.  I currently have another column that calculates the days betwen the rows and I am currently just looking at the totals and highlighting the highest period.
    Is this possible?  Any help or suggestions are appreciated.
    Thank you,
    Trevor

    This sounds totally possible,  Can you post a screen shot of your table to make responding more focused?  If you mean you want to:
    A) compute the difference (in days) between two date in the same row, then
    B) find the max duration (in days)
    Here is my take on this problem:
    D2 = C2-B2
    select D2 and fill down
    F1=MAX(D)
    to perform the conditional formatting (to highlight the max duration) select column D, then set up conditional formatting as shown in the 1st image

  • In AP invoice i need to make "Terms date " field to calculate the date automatically when i select the payment terms

    In AP invoice i need to make "Terms date " field to calculate the date automatically when i select the payment terms.
    How can i do this?

    Hi,
    You can select the Payment Term at PO Header Level.
    When you book an invoice, that Payment Term will automatically defaulted to Invoice.
    You can define Payment Term in AP.
    Payment terms have one or more payment terms lines, each of which creates one scheduled payment. Each payment terms line and each corresponding scheduled  payment has a due date or a discount date based on either a specific day of a month, such as the 15th of the month, or a number of days added to your terms date, such as 14 days after the terms date.
    Payment Terms (Oracle Payables Help)

  • How to Calculate the Time Between two days in ABAP

    Hi,
                  I have one scenario like i need to calculate the time between two days please can you suggest me.
    Thanks,
    Harinath

    Hi Peeleti,
                Check this code,
    DATA : DATE1 LIKE SY-DATUM VALUE '19830125',
           DATE2 LIKE SY-DATUM VALUE '20070219',
           DAYS1 TYPE I,
           WEEK1 TYPE I,
           MONTH1 TYPE I,
           YEAR1 TYPE I,
           C_YEARS1 TYPE I.
    CALL FUNCTION 'HR_99S_INTERVAL_BETWEEN_DATES'
    EXPORTING
      BEGDA           = DATE1
       endda           = DATE2
      TAB_MODE        = ' '
    IMPORTING
      DAYS            = DAYS1
      C_WEEKS         =
      C_MONTHS        = C_YEARS1
      C_YEARS         = C_YEARS1
      WEEKS           = WEEK1
      MONTHS          = MONTH1
      YEARS           = YEAR1.
      D_MONTHS        =
      MONTH_TAB       =
    *WRITE : / 'DAYS   = ', DAYS1,
            / 'WEEKS = ',WEEK1,
          /  'MONTHS = ', MONTH1,
          / 'YEARS   = ', YEAR1.
    Using this code you can calculate the No Of Days Between two dates. Based On days you will easily calculate the Hour. [  No of days * 24 ].
    Thanks.
    Reward If helpful.

  • How to get the date of first day of a week for a given date

    Hi gurus
    can any one say me how to get the date of first day(date of Sunday) of a week for a given date in a BW transformations. For example for 02/23/2012 in source i need to get 02/19/2012(Sunday`s date) date in the result. I can get that start date of a week using  BWSO_DATE_GET_FIRST_WEEKDAY function module. But this function module retrieves me the  start date as weeks monday(02/20/2012) date. But i need sundays(02/19/2012) date as the start date. So it would be really great if anyone sends me the solution.
    Thanks
    Rav

    Hi,
    The simplest way would be to subtract 1 from the date date which you are already getting in transformation routine, but instead of doing that subtraction manually which might need bit of errort, you can simply use another FM to subtract 1 from given date.
    RP_CALC_DATE_IN_INTERVAL
    Regards,
    Durgesh.

  • How to get the date of 60 days before 1999/03/01?

    Hi, I have a question about Date and GregorianCalendar here. I have a string "1999/03/01" and I would like to know the date that 60 days before 1999/03/01. What should I do it?
    I only went this far:
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
    String date = "1999/03/01";
    Date day = dateFormat.parse(date);
    GregorianCalendar calendar = new GregorianCalendar();
    : <--- ??
    So, can anyone please tell me what should I do next??
    -jxchou

    Put this in the search box for this forum at the right: add days +date
    The first 2 hits are about your question.
    The Forum search is your friend...

  • How to calculate the data in bex

    Dear all,
                i have a service order no and it current active status  and it time stamp details in my query
    example
    sevice orer no  posting date name    current active status  active status date    part aging
    800000243      15.01.2009   shahina part despatched          A     17.01.2007  
    in my ods i have
    sevice orer no  posting date name    current active status  active status date    part aging
    800000243      15.01.2009   shahina part despatched          A    17.01.2007  
    800000243      15.01.2009   shahina part pending               x    16.01.2007  
    800000243      15.01.2009   shahina part for asp                 x    17.01.2007  
    i want to calulate the aging of part pending to part despatched
    17.01.2009   -   15-01.2009   = 2 days
    i want to display in my bex like this
    sevice orer no  posting date name    current active status  active status date    part aging
    800000243      15.01.2009   shahina part despatched          A     17.01.2007      2
    ( in bex report i want to display only active status )
    can any one help me please to solve this issue
    Regards
    shahina

    Hi vamsi talluri ,
      i working in crm reports ( service ) here i want to calulate the differance between the old status that is inactive status date to part despathed date
    sevice orer no  posting date name    current active status  active status date    part aging
    800000243      15.01.2009   shahina part despatched          A     17.01.2007  
    in my ods i have
    sevice orer no  posting date name    current active status  active status date    part aging
    800000243      15.01.2009   shahina part despatched          A    17.01.2007  
    800000243      15.01.2009   shahina part pending               x    16.01.2007  
    800000243      15.01.2009   shahina part for asp                 x    13.01.2007  
    i want to calulate the aging of part pending to part despatched
    17.01.2009   -   13-01.2009   = 4 days
    i want to display in my bex like this
    sevice orer no  posting date name    current active status  active status date    part aging
    800000243      15.01.2009   shahina part despatched          A     17.01.2007      4
    in bex i am dispaying only active satus but i want calculate diff bet active status which i am dispalying in the bex analyzer and old status whaer the data are available in sercice order ods
    please help me how to perform the calculation
    Regards,
    shahina..!
    ( in bex report i want to display only active status )
    can any one help me please to solve this issue
    Regards
    shahina..!
    Edited by: Shahina A on Jan 21, 2009 6:13 AM

  • How we calculate the date difference between two list in SharePoint 2010

    Hi friend's....I have two list first is list1. In this list i have two coulmn start_date and End_date. In second list2 i have two column HolidayName and Holiday_date. Now i want two find the number of day in list1 Excluding Weekend and Holiday_date(that
    column from list2). How i will do ..? Please help me dosto..

    Thanks for reply...
    I have done the date difference in list1. But i want to Exclude the Holiday_date form list2.
    I have list1 - Start_date , End_date, Number_of_day(Exclude weekend and Holiday_date between Start_date and End_date )
    list2 - HolidayName, Holiday_date
    Now how i will calculate the Number_of_day in first list.

  • Calculate the date range from entered date

    HI
    My requirement is to get the data in a perticular intervals of posting date.
    Directly we can create a variable with interval on posting Date to have the required data but Here we need two have two varibles because in one varibale user enters posting date and in second variable user enters any number like 1,2,3....etc
    Let's say user enetered posting date as 30.08.2010 in the first variable and number 4 in the second variable.
    Finally out put range should be calculted from entred posting date 30.08.2010  date to four days back  
    i.e output  should be appear in the report  from 27.08.2010 to 30.08.2010.
    My question i can create first avariable on posting Date but  where shoud i create the second variable on which field.
    Please help me on this..points will be awrded.
    Regards,
    Siva Thottempudi.

    R you talking about the below to create new variable on the existing key figure
    Selecting Variables
    When you select characteristic values in the query definition, you can also select variables instead of fixed values. These act as placeholders and are only filled with fixed values when the query is executed.
    When selecting variables, you can also define new variables, change variables, or delete variables. These functions are always available to the right of the selection of the variable type.
    Selecting Variables
    1.      Choose Show ® Variables.
    2.      Under Type, select the variable type (such as Characteristic Value Variable, Hierarchy Node Variable) from which you want to select the variable.
    3.      Select one (or, in exceptional cases, more than one) variable from the list of available variables in the left window and add them (using the right arrow) to the right Selection window.
    Selecting Variable Value Range Limits
    1.      Choose Show ® Value Ranges.
    2.      Select your required operator from the dropdown box. You can choose from the following operators:
    ○       Between
    ○       Less Than or Equal to
    ○       Greater Than or Equal to
    ○       Less Than
    ○       Greater Than
    3.      Select the required value or values for the value range and choose . The input help appears in a new dialog box and displays the selection of variables under Show  ® Variables.
    4.      Under Type, select the variable type (such as Characteristic Value Variable, Hierarchy Node Variable) from which you want to select the variable.
    5.      Select the required variable and choose OK.
    6.      For the Between operator, two single values are required for the interval limits; the system automatically displays two dropdown boxes. In this case, repeat steps 3-5.
    7.      After you have set the value range, choose OK.
    8.      Add the selection to the right Selection window using the right arrow.

  • Calculate the date difference on essbase 9.3

    Hi Everbody,
    I want to calculate the difference between 2 date in essbase 9.3. Is any one did this practice ?
    I have done this but that is not a better way. so please share your thought with me.
    Regards
    Vikram Singh

    Hi,
    DateDiff function returns the difference (number) between two input dates in terms of the specified date-parts, following a standard Gregorian calendar.
    Syntax
    DateDiff ( date1, date2, date_part )
    date1+ is the number representing the input date between January 1, 1970 and Dec 31, 2037. The number is the number of seconds elapsed since midnight, January 1, 1970. To retrieve this number, use any of the following functions: Today(), TodateEx(), GetFirstDate(), GetLastDate(), DateRoll().
    Date-time attribute properties of a member can also be used to retrieve this number. For example,
    Product.currentmember.[Intro Date] returns the product introduction date for the current product in context.
    [Cola].[Intro Date] returns the product introduction date for Cola.
    date2+ A second input date. See date1.
    date_part+ Defined time components as per the standard calendar.
    DP_YEAR - Year of the input date.
    DP_QUARTER - Quarter of the input date.
    DP_MONTH - Month of the input date.
    DP_WEEK - Week of the input date.
    DP_DAY - Day of the input date.
    Edited by: Cnee on Jul 13, 2009 3:19 AM
    Edited by: Cnee on Jul 13, 2009 3:20 AM

  • How do i calculate the dates in this scenario

    I have a situation here and i am not able to think through it
    there are 4 date columns in a table and i need to do something like below
    First Record start date is the start date, and end date is the next start date -1
    Next start date is next start date, and end date is the first end date of the record set of the end dates
    Next start date pervious end date + 1 and end date is the current end date
    Next start date is the current date and next end date is the current end date
    for example lets say we have a table like below
    CustomerID CustomerType CustomerEffDt   CustomerTrmDt CustNationalBgnDt CustNationalEndDt
    1                  National           2013-08-05        9999-12-31      
    2010-11-08            2011-11-02
    Now my question is, we would have to calculate the customer effective start and begin dates and national begin and end dates based on the above criteria
    we would have to create 4 rows based on the above scenario
    I am going mad and not able to think through this
    Can somebody help me
    Thanks

    Declare @Example table (CustomerID int, CustomerEffDt date, CustomerTrmDt date, CustNationalBgnDt date, CustNationalEndDt date, otherstuff varchar(99))
    insert @Example Select 1, '3/19/2014', '9999-12-31', '3/19/2015', '2/19/2016', 'first'
    UNION Select 2, '3/19/2014', '9999-12-31', '4/19/2014', '5/28/2014', 'second'
    UNION Select 3, '2013-08-05', '9999-12-31', '2010-11-08', '2011-11-02', 'first example by OP'
    Select CustomerID,Num
    , case When Num = 1 Then '1/1/1900'
    when NUM = 2 then CustNationalBgnDt
    when NUM = 3 then DateAdd(day, 1, CustNationalEndDt )
    when NUM = 4 then CustomerEffDt End as startdate
    , case When NUM = 1 then DateAdd(day, -1, CustNationalBgnDt)
    when NUM = 2 then CustNationalEndDt
    when NUM = 3 then Dateadd(Day, -1, CustomerEffDt)
    when NUM = 4 then CustomerTrmDt End as EndDate
    From @EXAMPLE
    Cross Apply (Select 1 as Num UNION Select 2 UNION Select 3 UNION Select 4) as Numbers
    order by CustomerID, Num
    /* --Your result
    1 1 1900-01-01 2015-03-18
    1 2 2015-03-19 2016-02-19
    1 3 2016-02-20 2014-03-18
    1 4 2014-03-19 9999-12-31
    2 1 1900-01-01 2014-04-18
    2 2 2014-04-19 2014-05-28
    2 3 2014-05-29 2014-03-18 ---***
    2 4 2014-03-19 9999-12-31 --****
    3 1 1900-01-01 2010-11-07
    3 2 2010-11-08 2011-11-02
    3 3 2011-11-03 2013-08-04
    3 4 2013-08-05 9999-12-31
    CustomerID StartDate EndDate
    1 1900-01-01 2014-03-18
    1 2014-03-19 2015-03-18
    1 2015-03-19 2016-02-19
    1 2016-02-20 9999-12-31
    2 1900-01-01 2014-03-18
    2 2014-03-19 2014-04-18
    2 2014-04-19 2014-05-28
    2 2014-05-29 9999-12-31
    3 1900-01-01 2010-11-07
    3 2010-11-08 2011-11-02
    3 2011-11-03 2013-08-04
    3 2013-08-05 9999-12-31
    ;with mycte as
    select CustomerID, dt,col,row_number() Over(partition by CustomerID Order by dt) rn
    ,row_number() Over(partition by CustomerID Order by dt DESC) rn2 from @Example
    cross apply (
    values( CustomerEffDt,'CustomerEffDt'), (CustomerTrmDt,'CustomerTrmDt')
    , (CustNationalBgnDt,'CustNationalBgnDt'), (CustNationalEndDt,'CustNationalEndDt'))
    d(dt,col)
    Select m1.CustomerID,
    Case when m1.rn=1 Then '1/1/1900'
    When m2.col='CustNationalEndDt' Then dateadd(day,1,m2.dt)
    Else m2.dt end as StartDate,
    Case
    when m1.rn2=1 Then m1.dt
    When m1.col='CustNationalEndDt' Then m1.dt
    else dateadd(day,-1,m1.dt) End
    as EndDate
    From mycte m1 LEFT Join mycte m2 on m1.CustomerID=m2.CustomerID AND m1.rn=m2.rn+1
    Order by m1.CustomerID, m1.dt

  • Calculate the date diff

    Hi, The requirement is to calculate the diff between 2 date fields and display it. I could able to get the difference between the 2 date fields. But now the result column SHOULD DISPLAY the result ONLY if the 2 date fields have the date set ELSE it should be left blank(basically NULL shud be set to the result column in such cases).
    The formula which I have used to get the result is :
    (NOERR(date1)<>0 AND NOERR(date2)<>0)*(date1-date2).
    The above formula works fine and gives the result as desired except that it puts "0" even though the date fields doenst have a value.I have tried to use the ELSE part by giving "1/0" thinking it wud give me "#" but this didnt help me out anyway.
    Any inputs on this...

    Thanks for the response.
    That was an option which I also thought of and I wud use it only as a last rescue and trying if I can get some info to do it otherwise.
    The other option which I have in my mind is to just get this diff into the cube and this shud resolve but then again I hv to chg the BW structures and unnecessarily I wud be increasing the load to the cube.
    Any other option in Bex ...???

Maybe you are looking for