Average betweeen two dates

Hi All
I have five different adte fields:
DateA Date B DateC DateD DateE
How can i find the average number of days between any two given date fields?
Thanks All

Thanks,
When i tried to implement the solution: trinc(date1)-trunc(date2), i'm getting mismatch invalid datatypes, but both the dates are of the same datatype VARCHAR2-10?
Any ideas?

Similar Messages

  • Diff between Two dates

    I am Unable to find the Diffrence betweeen two dates. can you please help how i find the difference between tow dates.
    Thanks,

    Hi,
    As Bhushan showed, the result of subtracting one DATE from another is the number of days between them.
    If
    d1 is 06:00:00 on April 19, 2010, and
    d2 is 12:00:00 on April 20, 2010, then
    d2 - d1is 1.25, because d2 is 1 day plus 6 hours (6/24 = .25) days after d1.
    If you want the difference in months or years, use the MONTHS_BETWEEN function:
    MONTHS_BETWEEN (d2, d1)is the number of months that d2 is after d1, and
    MONTHS_BETWEEN (d2, d1) / 12is the number of years.

  • Average of a field between two dates

    Hi,
    I have a table with two fields. Date Field and Percentage field. For ex,
    Date Percentage
    1/1/2006 11
    1/4/2006 23
    2/4/2006 34
    11/11/2006 354
    1/4/2007 75
    10/09/2007 67
    2/3/2008 876
    I want to find the average(sum of percentage/total no) of Percentage field between two dates.
    I am passing only the end date. And, the start date I have to find according to the end date.
    For ex,if I am passing the end date as 10/09/2007, starting date should be 1/4/2007.
    And, if I am passing the end date as 11/11/2006, starting date should be 1/4/2006.
    For end date 2/3/2008, start date should be 1/4/2007.
    Starting date is taken as by considering the year end as April to March. So, I have to retrieve the average of the percentage field from April to the selected date as end date.
    thanks

    Getting the sum, number of rows and average since the last 1st of April to the current date :
    SQL> with tbl as
      2  (select to_date('01/01/2006','dd/mm/yyyy') as dt, 11  prct from dual union all
      3   select to_date('01/04/2006','dd/mm/yyyy') as dt, 23  prct from dual union all
      4   select to_date('02/04/2006','dd/mm/yyyy') as dt, 34  prct from dual union all
      5   select to_date('11/11/2006','dd/mm/yyyy') as dt, 354 prct from dual union all
      6   select to_date('01/04/2007','dd/mm/yyyy') as dt, 75  prct from dual union all
      7   select to_date('10/09/2007','dd/mm/yyyy') as dt, 67  prct from dual union all
      8   select to_date('02/03/2008','dd/mm/yyyy') as dt, 876 prct from dual)
      9  select dt, prct,
    10         sum(prct) over (order by dt range between dt-add_months(trunc(add_months(dt,-3),'yyyy'),3) preceding and current row) sum_prct,
    11         count(prct) over (order by dt range between dt-add_months(trunc(add_months(dt,-3),'yyyy'),3) preceding and current row) nb_prct,
    12         avg(prct) over (order by dt range between dt-add_months(trunc(add_months(dt,-3),'yyyy'),3) preceding and current row) avg_prct
    13  from tbl;
    DT             PRCT   SUM_PRCT    NB_PRCT   AVG_PRCT
    01/01/06         11         11          1         11
    01/04/06         23         23          1         23
    02/04/06         34         57          2       28,5
    11/11/06        354        411          3        137
    01/04/07         75         75          1         75
    10/09/07         67        142          2         71
    02/03/08        876       1018          3 339,333333
    7 rows selected.Nicolas.

  • PerformancePoint - 2010 Scorecard filter based on two data sources (Actual - OLAP/Target - Sharepoint List)

    Hi
    I have KPI's for tasks performed by specific groups within our organization, the actuals are determined by an MDX tuple formula against an AS OLAP data source:
    ([Change Task Assignment Group].[Group Subtype].&[GDC PM], [Measures].[Average task duration - m]) /1440
    The Task Name is provided by a filter, also looking at the AS OLAP data source.
    This woks well and allows us to have a single scorecard for the team, providing actuals depending on the task selected from the filter.  The problem comes in setting targets for the KPI's!  I can only set one target for each KPI and this is
    the same for which ever task is selected via the filter.  The target is stored in a SharePoint list.
    Is it possible to have targets for the different tasks driven by the same filter?  Can a single filter be configured to return values from two data sources to both the Actual KPI value and the Target value?
    Thanks

    A good solution. Liked it very much. Can you please make it a technet blog for others.
    [email protected]

  • Calculating difference between two dates in Variable Exits

    Hi,
          I need to calculate the difference between the two dates in months in Variable exits. I want the result in months so that I need to find out the Average Usage.
            How can I find the difference between them in months.
    Thanks
    Dave.

    Hi Christophe, Senthil
                                       Sorry for late response, I checked this  MONTHS_BETWEEN_TWO_DATES_NEW  in SE37/SE38 and about the date they are going to enter at query run time it should be like 03/03/2006 to 08/03/2006 and I should get in 5 months and or if the date range 03/15/2006 to 08/03/2006 and I should get like 4.5 months. Please could you tell me how to get the values in months or please give me a functional module so that I can use.
    Thanks
    Dave.

  • How to get two date difference in Day/hour/min/secs pl

    First of all,
    Hello to All, i am new to Oracle DB, but i have little experience in Other Database such as Sybase, sql server etc
    please kindly help me
    in DoctorChart table i have DocName,Id#,Citcotype,Medtype,AdmitDate,DischargeDate(both admitdate & Discharge date is date formatted columns)
    so how can i get the below differenceTime (which means Dischargedate-Admit Date in below format i.e, Day,Hours,Minutes,Seconds...)
    DoctorName, ID #, Citco type, MEDtype, DifferenceTime
    ========= === ======= ======= ===========
    Dr. KindaEmesko, 20045, Replace OutCard, ICH, 0 day 9 hours 11 minutes
    Dr. KindaEmesko, 20098, Replace OutCard, ICH, 1 day 2 hours 34 minutes
    Dr. KindaEmesko, 20678, Replace OutCard, ICH, 2 day 23 hours 52 minutes
    Dr. KindaEmesko, 20212, Replace OutCard, ICH, 4 day 1 hours 00 minutes
    Dr. KindaEmesko, 20345, Replace OutCard, BED, 3 days 14 hours 15 minutes
    Dr. KindaEmesko, 20678, Replace OutCard, BED, 9 days 21 hours 52 minutes
    Dr. KindaEmesko, 20015, Signature Overlay, Rest, 0 days 3 hours 29 minutes
    Dr. KindaEmesko, 45678, Signature Overlay, Rest, 0 days 1 hours 29 minutes
    Same way how can i get the Average Time for the above result (without ID columns)
    DoctorName, Citco type, MEDtype, Avg DifferenceTime
    ========= === ======= ======= ===========
    Dr. KindaEmesko, Replace OutCard, ICH, 2 day 1 hours 00 minutes
    Dr. KindaEmesko, Replace OutCard, BED, 6 days 17 hours 15 minutes
    Dr. KindaEmesko, Signature Overlay, Rest, 0 days 2 hours 29 minutes
    Please just tell me how to get the two dates difference as day/hour/minute format
    as well as how to get avg ( two dates difference as day/hour/minute format)
    Please Help me
    Thanks in advance

    Well, instead of all these suggested manipulations you can simply use intervals. Oracle uses day as a unit in date arithmetic, so Dischargedate-Admit Date is number od days between two dates. Built-in function numtodsinterval can be used to convert it into interval. For example:
    SQL> with t as (
      2             select trunc(sysdate) - 2 Admit_Date,
      3                    sysdate            Discharge_Date
      4               from dual
      5            )
      6  select  numtodsinterval(Discharge_Date - Admit_Date,'DAY') Hospital_Stay
      7    from  t
      8  /
    HOSPITAL_STAY
    +000000002 00:01:08.000000000
    SQL>  SY.

  • Query between two dates

    Hi,
    I have table like this.
    Id           in_date               value
    2          05-Jun-08          5.3
    3          08-Jun-08          5.2
    4          08-Jun-08          5.3
    5          08-Jun-08          5.8
    6          10-Jun-08          7
    7          10-Jun-08          5.6
    8          11-Jun-08          2.6
    When I query for average value between two dates, it should return average and if there is no entry for any dates it should return 0 for that date. Here is sample output for dates between 05-Jun-08 and 12-Jun-08.
    In_date           value
    05-Jun-08     5.3
    06-Jun-08     0.0
    07-Jun-08     0.0
    08-Jun-08     5.43
    09-Jun-08     0
    10-Jun-08     6.3
    11-Jun-08     2.6
    12-Jun-08     0
    Please help me to write query on thisThanks,
    Sujnan

    SQL> with t as (
      2             select 2 id,to_date('05-Jun-08','dd-mon-rr') in_date,5.3 val from dual union all
      3             select 3,to_date('08-Jun-08','dd-mon-rr'),5.2 from dual union all
      4             select 4,to_date('08-Jun-08','dd-mon-rr'),5.3 from dual union all
      5             select 5,to_date('08-Jun-08','dd-mon-rr'),5.8 from dual union all
      6             select 6,to_date('10-Jun-08','dd-mon-rr'),7 from dual union all
      7             select 7,to_date('10-Jun-08','dd-mon-rr'),5.6 from dual union all
      8             select 8,to_date('11-Jun-08','dd-mon-rr'),2.6 from dual
      9            )
    10  select  t2.in_date,
    11          nvl(t1.val,0) + t2.val val
    12    from  (
    13           select  in_date,
    14                   avg(val) val
    15             from  t
    16             group by in_date
    17          ) t1,
    18          (
    19           select  min_in_date + level - 1 in_date,
    20                   0 val
    21             from  (
    22                    select  min(in_date) min_in_date,
    23                            max(in_date) max_in_date
    24                      from  t
    25                   )
    26             connect by level <= max_in_date - min_in_date + 1
    27          ) t2
    28    where t2.in_date = t1.in_date(+)
    29    order by t2.in_date
    30  /
    IN_DATE      VAL
    05-JUN-08   5.30
    06-JUN-08    .00
    07-JUN-08    .00
    08-JUN-08   5.43
    09-JUN-08    .00
    10-JUN-08   6.30
    11-JUN-08   2.60
    7 rows selected.
    SQL> SY.

  • Working days between two date fields and Changing Factory Calendar

    Hi,
    I have to calculate working days between two date fields excluding the weekends and public holidays for Switzerland.
    I have written the routine using factory calender and its working fine except for two problems now:
    1. If any one of the date field is empty then teh rsult should be zero.
    2. And the below code is working from 1996 but my cleints wants it to work for years before 1996 as well.
    I also tried to change the Start date in SCAL for factory calendar but it says enter values between 1995 to 2020.
    I am new to ABAP. Please help me how i can achieve these for below code.
    DATA: IT_HOLIDAYS type TABLE OF ISCAL_DAY,
          IS_HOLIDAYS TYPE ISCAL_DAY.
    DATA: T_DATE TYPE SY-DATUM,
          P_DATE TYPE SY-DATUM.
    DATA : X_DATE(4) TYPE C.
    DATA: CNT TYPE I.
    REFRESH : IT_HOLIDAYS.
    CLEAR : IT_HOLIDAYS.
    T_DATE = SOURCE_FIELDS-/BIC/ZCCCHP812.
    P_DATE = SOURCE_FIELDS-/BIC/ZCCCHP810.
    CALL FUNCTION 'HOLIDAY_GET'
    EXPORTING
    HOLIDAY_CALENDAR = 'CH'
    FACTORY_CALENDAR = 'CH'
    DATE_FROM = P_DATE
    DATE_TO   = T_DATE
    TABLES
    HOLIDAYS = IT_HOLIDAYS
    EXCEPTIONS
    FACTORY_CALENDAR_NOT_FOUND = 1
    HOLIDAY_CALENDAR_NOT_FOUND = 2
    DATE_HAS_INVALID_FORMAT = 3
    DATE_INCONSISTENCY = 4
    OTHERS = 5.
    DESCRIBE TABLE IT_HOLIDAYS LINES CNT.
    X_DATE = T_DATE - P_DATE - CNT.
    RESULT = X_DATE.
    Please help
    Regards
    Zabina
    Edited by: Syed786 on Nov 2, 2011 9:15 AM

    Hi Zabina,
    Try this function module  'DURATION_DETERMINE'.
    Give the factory calendar and unit as DAY
    With regards,
    Rajesh

  • Logic at reporting level to compare two dates .

    Dear Friends,
    I have a scenario here , where i have a counter keyfigure in my DSO which has constant value 1 . there is two dates : Stock issue date & stock receipt date .  At the reporting level , in selection screen there is an input on stock receipt date . Now i want to show key figure counter for which stock issue date lies between the stock receipt date which the user enters .
    Kindly suggest on this matter .
    Thanks & regards,
    Ashutosh Singh

    1. Create a customer exit variable on Stock issue date. Pass on the value the user enters through exit to this variable.
    2. Create a New formula with the counter keyfigure and restrict it based on the customr exit variable.
    This will work correctly if Stock issue date and stock receipt date are not displayed in the report.
    If it is displayed, then if the stock issue date lies between the stock receipt date it will have the value as 1 else 0.
    Hope this helps.
    rgds, Ghuru

  • Formula for compare two date fields

    Please help me,
    There are two date fields in DSO , I want to create a key figure by Query Designer, the condition as blow
    Count ( If field DateA > field DateB = 1 else 0 ).

    http://www.sd-solutions.com/SAP-HCM-BW-Replacement-Path-Variables.html
    create 2 formula varaibles like above and comapre it

  • How can I reference records outside the two date parameters?

    Hi all,
    I have a query that fetches records based on the two date parameters defined (Startdate and Enddate).
    If the Startdate is 2014-12-01 and the Enddate is 2014-12-12, I want to pull records outside these two date parameters, that is      2014-09-01 and 2014-11-30.
    I want to add up the records from  2014-09-01 and 2014-11-30 and include them in one of the columns in my report.
    I tried using this query:
     SUM(CASE WHEN FilteredIncident.Statuscodename IN ('QUEUED', 'ASSIGNED') AND (EnteredOn >= '2014-09-01' AND EnteredOn<= @StartDate) THEN 1 ELSE 0 END) AS OpenRecords
    Please help with any ideas..thanks

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you probably need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    There is no such crap as a “status_code_name” in RDBMS. It has to be a “<something in particular>_status”; think about how silly that data element name is! Want to keep going and have a “status_code_name_value_id”? LOL! 
    The name “Filtered_Incident” is also wrong. Tables are sets, so unless you have only one element in this set, the table name should be a plural or (better) collective name. But a better question is why  did you split out “Filtered_Incidents” from “Incidents”?
    Would you also split “Male_Personnel” and “Male_Personnel” from “Personnel”? 
    Get a book on data modeling and learn some basics. 
    >> I have a query that fetches records [sic: rows are nor records] based on the two date parameters defined (report_start_date and report_end_date). If the report_start_date is 2014-12-01 and the report_end_date is 2014-12-12, I want to pull records [sic]
    outside these two date parameters, that is 2014-09-01 and 2014-11-30. I want to add up the records [sic] from 2014-09-01 and 2014-11-30 and include them in one of the columns in my report. <<
    Having no DDL and no sample data makes this hard. Does your boss make you program without any documentation, DDL, etc? This spec is vague; you say to do a total, but show a count, etc. 
    One of the many nice things about DATE data types is that the BETWEEN predicate works with them, so you can quite writing 1960's BASIC predicates with primitive logic operators. 
    Here is a guess: 
    SELECT SUM(CASE WHEN incident_date BETWEEN '2014-09-01' 
               AND @report_start_date THEN 1 ELSE 0 END)
           AS open_record_cnt 
      FROM Incidents
     WHERE incident_status IN ('QUEUED', 'ASSIGNED')
        AND incident_date <= @report_end_date; 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • How to calculate the month difference between two date char. in Query?

    Customers would like to see how many months passed between two date type of characteristics (e.g., the month difference between the current date and the scheduled delivery date in the record) and put the result into the column as KF. 
    We would have to grab the fiscal year/period kind of value and then do the subtraction, e.g., if the current date value is 2/28/2008 and the scheduled delivery date value in the record is 12/01/2007, the correct result should be 2 month difference between these two date values, but could someone here give us the technical light on how to make this happen in query design?
    Thanks and we will give you reward points for the correct anwsers!

    Hi Kevin,
    The Badi is RSR_OLAP_BADI.
    You can create an implementation using Transaction  SE18.
    The implementation is per cube and is defined in the filters.
    In the Implementation you have the following methods :
    1. Define : Here you will provide the Keyfigure you need as a virtual one.
    2. Initilialize : Any Init Function you want to do.
    3. Compute. This is called per datarecord and here you can cimpute your value.
    Hope this helps.
    Pralay Ahluwalia

  • How to generate a number from two dates

    I am 'new' at this of using Numbers for anything.  What I want to do AND I can't seem to figure it out, is to generate a 'days total' from two dates.  I get paid S.S. on the 2nd Wednesday of each month.  I have X number of dollars to spend.  In order to view each day how much money I have for the rest of the month, I need to be able to obtain how many days are left in the period.  I know what the fixed day is for the end and could key that in.  I want it to be able to take the current day for the calculation without my having to key IT IN each day.  Then I could use that returned number for other functions.  I did look into "Functions" screen on the right hand side, read them several times, tried some but have not succeeded.  Can someone here help this 68 year young man to figure this out?  Thanks

    you can use the function TODAY() to get the date.
    then you can compute a duration (the difference between two dates).  Data/time is a single type of variable in Numbers.  Meaning that a complete date/time value includes both a date and a time.  When you enter one without the other Numbers assumes the other portion.
    you can subtract any two dates to get the duration.
    The format for a date is:
    1/2/2015 12:09A
    2 Jan 2015 12:09A
    a duration would look like:
    3w 4d 6h 15m 45s 76ms
    Three weeks, four days, six hours, fifteen minutes, forty five seconds, seventy six milliseconds
    you can use any combinations of these parts for a duration
    A1
    =TODAY()
    B1
    =EOMONTH(TODAY(),0)
    C1
    =B1−A1

  • How to call two data blocks at a time.

    hi all
    i want to call two data blocks at a time on function when button pressed.
    how can I it?
    many thanks

    Many thanks that you people reply,
    I am working in oracle form developer 6i and database 10g.
    I have a form that have three data blocks,
    first block have text boxes and search button,and next two blocks display records on the basis of search criteria that is inserted in the first block and when is clicked on save button.
    the data that is to b displayed is from two different tables.
    i used Go_block('my_block')
    and call other block with the same method.
    kindly guide me how can i do it.
    Thanks in advance

  • How to query two data blocks simultaneously?

    Dear all,
    Need your inputs on the following problem statement...
    Existing Functionality:
    We have two data blocks A (Parent) and B (Child) in a relationship. Both data blocks refer to different tables.
    Data block A is the query data block and for a single record in block A we can have multiple records in block B. Multiple records in block B are shown one at a time after executing a query, this is implemented by using a list item C (belongs to a third block).
    For example
    Let us say block B can have 5 different types of entries for each record in block A. In this case the list item C will have 5 values corresponding to these entries. Once the query is executed, block B will show the default entry for the queried record in block A. To see other entries for the record user can select the required value in list item C and corresponding entry in block B will be fetched.
    Requirement:
    Our requirement now is to enable querying upon both data blocks A and B simultaneously. To implement this I replaced data blocks A and B with a single data block X which is based on the join of the two tables referred by the Data blocks A and B earlier. As the fields should allow insert, update, delete operations we did not use a view here.
    Issue:
    Now the problem is, each record in block A for which block B had multiple entries earlier is now getting listed multiple times because of the join.
    I have tried but could not find any solution for this. I would appreciate if any of you can suggest how we can query both blocks simultaneously without affecting the existing functionality.
    Thanks,
    Amit

    I don't understand your requirement in detail. I try to repeat what i understood so far.
    You have a master-block A based on a table A and a detail-block B based on a table B. So far so good. You can now query based on conditions just the datablock A, because B is a detail and therefore can only be queryied in context of block A.
    Your reuirement is to query on both blocks A and B and find block in B also without giving conditions for the relevant block A.
    Is it that ?
    What i don't understand, what is block C used for?
    An idea for the querying of block B's data: Create Non-database-items items in block A for the search-criteria you need on block B and make them Queryable.
    In the PRE-QUERY-trigger on block A build a WHERE-condition if that search-criteria is entered, something like
    IF :BLOCK_A.SEARCH_CRITERIA_FOR_BLOCK_B IS NOT NULL THEN
      SET_BLOCK_PROPERTY('BLOCK_A', ONETIME_WHERE, 'WHERE PKVALUE IN (SELECT FKVALUE_TO_A FROM TABLE_B WHERE FIELDVALUE=' ||:BLOCK_A.SEARCH_CRITERIA_FOR_BLOCK_B)');
    END IF;This would query also records to A for which you want to have the B-records. So you could keep block-structure up to master-detail.

Maybe you are looking for

  • Slightly off-topic, but Kudos to Creative's ebay out

    I ordered travelsound speakers off the outlet. it said no power adapter, no case, just the speakers and mini-cable. Well, holy cow, it arri'ved today and it was a blister packed brand new unit with power adapter/case! I'm using 'em with my zen as an

  • Link to download - Enterprise Portal Sneak Preview Version

    Hi Guys, Can somebody send me the link to download Enterprise Portal Sneak Preview Version. Thanks, mini

  • Blue Snowball not recognized

    I'm completely confused over this... I just installed Logic and was playing around with it this morning. Singing into a blue snowball mic worked fine until out of nowhere, it started recording from the built-in mic. So I make sure in system preferenc

  • Error after updating to iTunes 7.0.2 in regards to QuickTime version

    Quick Time version 7.0.4 is installed, iTunes requires Quick Time version 7.1.3 or later. Please reinstall iTunes. this is the message I am recv'g after downloading the 7.0.2 version of iTunes. I have uninstalled iTunes and Quick time and reinstalled

  • Windows 8 operating system + applications requiring 32-bit oracle client

    Hi, We are trying to install oracle 32 bit client on Windows 8 opertaing system 11.2.0.1 Have done so successfully on Windows 7 but  Windows 8 says doesn't meet minimum environemnet requirements. We have a 32-bit appliactuion which requires oracle cl