Difficult time period calculations

I have a monthly report where I have to add up periods of time between different records, without counting any overlapping time twice. Each record has its own start and stop date/time. The length of time from each record's start to its stop can be anything from 1 minute to the entire month. So for example, if there was 1 record that covered the whole month, I wouldn't need to look at any other records, because the whole month is covered. But if not, then I have all these pieces of time covering various parts of the month, some overlapping, some not.
If A starts at 1/1/01 0800 and
stops at 1/1/01 1200, and
B starts at 1/1/01 0900 and
stops at 1/1/01 1300, then I want to see the combination of these 2 as 5 hours. Other records C, D, ... could be entirely within this time period, or completely disjoint, or partially overlapping it. Again, I can't count any overlapping time twice. I have some lengthy code that does the job, but it takes a long time to run, because I create temp records that reflect the time periods found so far, and I don't add any new temp records that overlap the ones already created. It takes a long time to do all the comparisons. Anybody have any clever ideas for doing this faster?

Mike,
I believe this should work for you:
DECLARE
CURSOR c1 IS
SELECT start_date, end_date
FROM test_table
ORDER BY start_date;
v_total_time NUMBER := 0;
v_start_date DATE;
v_end_date DATE;
BEGIN
FOR r1 IN c1 LOOP
IF r1.start_date > NVL (v_end_date, r1.start_date - 1) THEN
v_start_date := r1.start_date;
ELSIF r1.end_date > v_end_date THEN
v_start_date := v_end_date;
END IF;
IF v_start_date IS NOT NULL THEN
v_total_time := v_total_time + (r1.end_date - v_start_date);
v_start_date := NULL;
v_end_date := r1.end_date;
END IF;
END LOOP;
DBMS_OUTPUT.put_line ('Total time: ' | | TO_CHAR (v_total_time) | | ' Days.');
END;
/

Similar Messages

  • Arbitrary time period calculation.

    How to do time series calculations for custom time series which are not sequential.
    We have time period called diet which is not sequential like calender date Example given below :-
    May 2012 Diet starts from 24/04/2012 to 16/06/2012 And May 2011 Diet starts from 01/02/2011 to 31/05/2011 diff
    100 50 50
    we need to compare May 2012 diet to May 2011 diet and create a difference column and also need to calculate variance on this. Also need to add other dimension like geography and status
    For this i tried to use Ago function but it wont allow us to calculate as they are not sequential
    Let me know if there is any solution.
    Thanks
    prabhu

    Any one on this ....

  • Time Period Calculation

    Hi Experts,
    My requirement is I have equipment 'E'  and this is assigned to some work from 8am to 2 pm.
    If it is again assind to work for the same period or time period which is in touch with between 8 am and 2pm. I have to giva a error.
    Is there any function module to calculate this.
    Or Please send some logic.
    Thanks & Regards,
    B. V. Rao
    Edited by: bala virupaksha on Nov 7, 2008 12:41 PM

    Hi,
    Hi Surabh,
    I am also doing that.
    Are you trying in the internal table? The logic should be via Database table.
    so you need to create a DB table with fields like
    equipment
    start_timestamp  " - Not just time
    end_timestamp           " - Not just time
    To find if the time clashes between already given time, you can build logic like looping through all the timestamps of the given
    equipment and ...
    if new_start_timestamp > db_start_timestamp and
      new_start_timestamp < db_end_timestamp.
       "  stop from proceeding.
    elseif new_end_timestamp > db_start_timestamp and
             new_end_timestamp < db_end_timestamp.
       "  stop from proceeding.
    elseif new_start_timestamp < db_start_timestamp and
             new_end_timestamp > db_end_timestamp.
       "  stop from proceeding.
    else.
    " You can proceed
    endif.
    Cheers,
    Kothand

  • Report workload by calculating how many versions of SharePoint list items created in a certain time period

    I have a total of 66 SharePoint 2010 lists - yes, 66! - each lists contains between 1500 and 3200 list items.  My employees update these various list items throughout their workday.  Each update to a list item creates a new version of the list
    item.  On average each list item will have anywhere from 5 to 10 versions before it is done.  I need to create a report that tells me how many list items they've updated in a certain time frame.  I have come close but still cannot arrive at
    the data I'm looking for. 
    This is what I have so far:
    I've created a report using SQL Report Builder 2008 v3 where I've filtered it to show only items MODIFIED between, for example, Feb1 and Feb28.  Of those records, I want the report to tell me how many versions were created during that time
    frame.  The result is one list item with 5 total versions.  Versions 1.0, 2.0, & 3.0 were created on 12/12/14.  The last two versions, 4.0 and 5.0, were created on 2/24/15.  Therefore, the answer I'm looking for is 2 because they
    created 2 versions between Feb1 and Feb28.
    However I get the following results using these queries:
    If I do a =Sum(Fields!owshiddenversion.Value) in the expression field I get the total versions which is 5
    If I do a =Count(Fields!owshiddenversion.Value) in the expression field I get the instance which is 1
    Is there a way to count ONLY the number of versions created in a time period?  Is there another hidden field in SharePoint that I can use in the expression that will give me results I'm looking for?

    Hi Rafael70,
    Per my understanding that you have already get all the need fields and informaiton of the updated version of list items and now you want to calculate how many versions of SharePoint list items created in a certain time period, you can't get desired result
    using sum and count function, right?
    I have tried to tested on my local environment but because I am not clear what is value in the field "owshiddenversion", I assumed you have two datatype parameters (StartDate and EndDate) to help filter the report in a certain time period.
    Generally, if you have add the filter correctly, it will filter the correct number's updated version in this time period, I would like you to provide details information as below to help better analysis the requirements:
    Could you please provide sample data of the table.
    Please provide snapshot of the report structure you have currently designed.
    Please try to provide all the expression you have used.
    If you still have any problem, please feel free to ask.
    Regards,
    Vicky Liu
    Vicky Liu
    TechNet Community Support

  • Not permitting time period to be overlapped....

    Hi ,
    I have the following table..in Oracle10g Standard Edition:
    SQL> desc ref_dikaioum_meres_ektos_edras;
    Name                          Type      Nullable Default Comments
    SEQ_CODE_DIKAIOUM_EKTOS_EDRAS NUMBER(5)                          
    SEQ_CODE_ERGAZOMENOY_TYPE_ID  NUMBER(5) Y                        
    DATES_APO                     DATE      Y                        
    DATES_EOS                     DATE      Y                        
    DAYS                          NUMBER(3) Y  How is it possible to define a businness rule(a constraint) that for a specific "SEQ_CODE_ERGAZOMENOY" not to permit new records to be inserted if the time_period(dates_apo...means date_from) and (dates_eos... means dates_to) is overlapped to another time period....
    For example:
    If there is a record .... seq_code_ergazomenoy_type_id=12 , dates_apo= '01/01/2007' , dates_eos='31/12/2007' ...
    and the user tries to insert a record like this.....
    .... seq_code_ergazomenoy_type_id=12 , dates_apo= '01/05/2007' , dates_eos='31/10/2007' ...
    or
    .... seq_code_ergazomenoy_type_id=12 , dates_apo= '01/05/2007' , dates_eos='31/01/2008' ...
    or
    .....seq_code_ergazomenoy_type_id=12 , dates_apo= '01/07/2006' , dates_eos='31/01/2007' ...
    or
    .....seq_code_ergazomenoy_type_id=12 , dates_apo= '01/01/2006' , dates_eos='31/01/2008' ...
    the system won't permit to insert it.....
    thanks a lot
    Simon

    Have you considered using 3360's suggestion of a materialized view with a check constraint?
    Like I said, it's really difficult to do this correctly, especially with triggers. In particular:
    1. Your package (or temporary table, or whatever) needs to able to store an arbitrary number of "records", not just one. If it only stores one, it won't correctly handle statements like INSERT INTO...SELECT...FROM where the SELECT returns more than one row. Tom's example uses an "index by" table of ROWIDs for this purpose.
    2. You need some sort of locking mechanism because you can't "see" changes that other, concurrent transactions have made but haven't committed yet. If you can't see them, you can't be certain that they their changes don't conflict with yours. The lock needs to prevent more than one transaction from inserting or updating rows for a given "domain" ("seq_code_ergazomenoy_type_id" I think in your case) at the same time. Tom's example uses DBMS_LOCK for this purpose, but...
    3. To handle serializable transactions, the lock needs to "persist" after you commit, at least until all other transactions that started before you committed have committed or rolled back themselves. DBMS_LOCK doesn't do this, but SELECT...FOR UPDATE can.
    In any case, if, for the moment, we ignore these important but difficult-to-address issues, and we ignore the "seq_code_dikaioum_ektos_edras" column (since I am not clear on how you want to use it), the logic for the query that finds the overlap (like in your after statement trigger) should be something like this (for a single record):
    declare
        n integer;
    begin
        select
            count(*)
        into
            n
        from
            dual
        where
            exists
                select
                    null
                from
                    ref_dikaioum_meres_ektos_edras     
                where
                    seq_code_ergazomenoy_type_id = pkg_ref_dikaioum_meres_chk.v_code_ergazomenou      
                    and
                    dates_apo < pkg_ref_dikaioum_meres_chk.v_dates_eos
                    and
                    dates_eos > pkg_ref_dikaioum_meres_chk.v_dates_apo
        if (n > 0) then
            raise_application_error(-20020,'error_message');
        end if;
    end;Tom's example loops through the rows identified in the "index by" table to perform this check for each "new" row.
    The "materialized view" approach basically does the same thing using a similar query. It "counts" the number of overlapping rows. When a transaction commits, the materialized view refreshes. A check constraint on the "count" column in the underlying table (that stores the "materialized" results of the view) prevents the "count" from being anything other than zero. If it is, the refresh fails.
    I wonder if your code is giving "false positives" because of the way you're using "seq_code_dikaioum_ektos_edras". Your SELECT statement could be returning the row that was just inserted because it has the greatest "seq_code_dikaioum_ektos_edras" and the row "overlaps with itself".
    Hope this helps.

  • Foreign currency conversion not picking up rate or time period

    I am running the standard FX conversion (standard stored procedure - fxtrans.lgx) on SAP BPC MS version 7.5 , but everytime I run the package, even though I choose a particular day,  it seems to run for multiple time periods.
    In the formula log  I get more than 50 of the following:
    10000400 - 4 rows calculated
    10000400 - 0 rows updated
    10000400 is the TIMEID for my currency conversion.
    Also, when I look at the result, even though I have entered 1 as my conversion fator I get a multiple of 18.  I tried to change the conversion factor, but no matter what I do for no matter what entity and no matter what LC I always end up with a multiple of 18.
    Any ideas for me?
    Thanks

    Hi,
    This sounds strange. Can you post your script logic file and a small extract from your time dimension please?
    Tom.

  • Automatic update value after time period passes

    Hi,
    In my application on page 8 I have an item which value is to be changed from one value to another depending on a time period. At first the item has value 1. Then we set it on value 2 and we also set a time period, for example 5 days. So after that period the value should automatically change on the value 1.
    On page 1 there is a region with a list entries, subjects which have the value 2 set. I want this list to change according the change of value.
    Does anyone know how to do this? I am a bit clueless...
    Thanks
    Regards,
    Leila

    There appears to be logical issue here.
    a) The value will be incremented only when user visits the Page 8 . If user does not visit Page 8 then the change will not occur
    b) If the user visits Page 8 but does not save the change (commit) even then the change would not come into effect.
    Can this not be handled through a scheduled job that runs on the underlying tables at per-determined intervals/time? Say , once a day?
    If the above 2 points do not affect you then you can try the Process route.
    i) Write a OnLoad Before Header or After header process on Page 8
    ii) In this process find out whether the required/preset interval has elapsed on not
    iii) If the criteria is met then change the value of the Page 8 as well as Page 1 items using bind variable sysntax in the Process
    :P12_ITEM := '2' ; -- or whatever you want.
    :P1_ITEM := :P12_ITEM;How to figure out the interval? If it is date/time based then use SYSDATE. If it is something else , you need to figure out the interval calculation that works for you.
    Regards,

  • Life time of SSD and alternative after time period

    Please clerify me the life time of SSD and HDD in term of calculation with respect to use and time period?
    Clarify me, If my SSD drive get inoperable after warrenty period than alternative to make situation nomal. If SSD of notebook became inoperable than my OS and other installed s/w will be operable or not?

    Hi Brad
    I can copy the code from routine #1 into my routine #911 inorder to restirct the display of output type in delivery header. But as mentioned by you this routine is not triggered at the time of PGI. ( I checked at the time of PGI )
    If i link my output type LD00 with Requirement #1 routine then it will be triggered at the time of PGI, but here the o/p is linked with Requirement #911.
    Pls let me know if any thing wrong i mentioned...

  • HT204406 I am having a very difficult time with accessing my music from the cloud.  I need to have itunes open on my laptop in order for it to work.  And as soon as I close out itunes on my laptop, it gives me a warning that all users will be logged out. 

    I am having a very difficult time with accessing my music from the cloud.  I need to have itunes open on my laptop in order for it to work.  And as soon as I close out itunes on my laptop, it gives me a warning that all users will be logged out.  Help!!!

    Where are iTunes files located?
    No, I do not mean just the music.  Copying just the media/music files or the media folder creates problems.

  • Closing characteristic after a time period

    Dear All,
    I am looking for a way to close an inspection charcateristic automatically after a certain time period.
    I have 3 characteristics for my inspection lot. The first should be closed 20 hours after generation of the inspection lot. The second 15 hours after that and the third 5 hours after that.
    Is there a way to do it?

    You can only make automatic UD for inspectoin lots if you meet the other requirements, which I doubt you do.  I.e. all required characterisitics have a status of 5 and all of those use a fixed scope.  You could make all your characterisitcs optional but that could lead to a whole bunch of non-processed lots.   I.e. if the wait period is met, the lots will be closed out.   This might be problems if some day the lab falls behind or is gone over a long planned outage.  It also runins the ability to indicate to techs the optional vs required characteristics!
    FF

  • How do you set the time period on IMAP email accounts (razr maxx)

    Hi Guys -
    Does anyone know how you can set the time period that the stock email will keep the already downloaded messages for IMAP email accounts?
    Mine never seems to show more than a couple of days worth at a time. I'd ideally like to be able to see at least 2 weeks worth of messages without needing to download them again!
    On other phones I've had there was a setting in the menu, but either I can't find it...or it's not there. I've found the setting for how OFTEN it checks the accounts, but not the setting I am seeking.
    Your help is appreciated!
    Best Wishes for the Holiday Season.
    -Rich

    Hey Rich.  Once in 'settings,' there should be a "days to sync' under the 'data usage' section.   You don't have that?

  • Is there a way to create a smart playlist that lists my top 25 plays from a specific time period (i.e. - top plays from the last 90 days)?

    Is it possible to create an itunes smart playlist that lists my top 25 most played songs in a specific time period (i.e. - the last 90 days)?  It seems that any "most played" list I create counts every spin a track has had in it's history of being in my library. 

    The challenge is is not to determine which of the tracks that have been played in the last X days has been played most since the beginning of time, but which have been played most in the last X days. iTunes can do the first one but it simply doesn't have the power to do the second.
    tt2

  • Warning "Time of Calculation 'Before Aggregation' is obsolete" in BI 7.0

    Hi Friends,
    We have recently upgraded our BW system from BW 3.1 to BI 7.0. While executing one of the query in BI 7.0 i am getting the Warning Message "Time of Calculation 'Before Aggregation' is obsolete". I can run the query by ignoring the message and get the results. But I am not getting the correct result for some of the calculated key figures which has setting for Time of calculation as "Before Aggregation".
    After doing some research i found that before aggregation is not allowed in BI 7.0. We are using queries created in 3.x environment. There is some work around which talks about creating new calculated key figure with after aggregation setting and all. But in my case it not feasible as there are so many queries based on those calculated key figures.
    Does any one had the similar situation? Is there any other way to correct this problem?
    I would appreciate your help in this regards.
    Thanks,
    Manmit

    Hi
    Try SAP notes 935903.
    Symptom
    Calculated Key Figures "Existance Indicator" with aggregation behaviour "Before Aggregation" will get now with NW 2004s warning popup "Time of calculation 'Before Aggregation' is obsolete" during execution.
    this may be helpful.
    Also Check the below thread
    /message/2986338#2986338 [original link is broken]
    Regards
    Shilpa
    Edited by: Shilpa Vinayak on Oct 10, 2008 4:23 AM

  • Hyperion planning data form in smartview: problem with summary time period

    We are using Planning ver. 11.1.2.2.300.20 and smartview 11.1.2.2.300 (build 070)
    We use common Data Form:
    In columns: Periods (Descendants including YearTotal - with no checkbox on start expanded)
    In Rows :accounts
    In some of our users computers,
    When they open Data Form in Excel (with Smart View) - its appears very strange:
    Summary Accounts are displayed as level 0 account in the summary Period columns (i.e. not in grey) and permit entering data.
    In addition when Entering data in summary time period (i.e. Year or Quarter),
    strangely,  the data doesn't  spread to the descendants months (level 0) .
    This phenomenon occurs just in few of the computers.
    Please help, how can we overcome this problem?
    Thanks and Regards
    Tami Kedem

    Hi Celvin,
    Thanks for your rapid response!
    All computers have the same version of planning and smartview.
    The computers where the Periods spreading and aggregation properties in Data form are not working,
    do work wonderfully when opening the Data forms in the web.
    I've tried everything, (remove suppressing, validations etc.):
    In all kind of data forms the spreading and aggregation properties on summary time periods are not working in smartview -
    and summary accounts on rows are not displayed in grey and permit entering data.
    We remove and reinstall MS-Office (2007) from the problematic computers, but it didn't help.
    Do you know if there is any kind of settings or softwares that might cause this phenomenon
    i.e. interrupts the smartview translation of the web Data Forms.
    Thank and best regards,
    Tami Kedem

  • Query for Old Data that does not match New Data within a given time period

    Hello all,
    One of the reports I need to create is for all associates who went from one department to another within a given time period. The way I ran this report in Reportsmith (pulling from our old system) was to compare the dept field from the beginning date to the dept field at the end date and it would give me those associate's that had moved. I had to do it this way b/c dept changes can happen using several different types of actions (supv change, promotion, etc.), none of them exclusive to just dept changes. We are now using Oracle HRMS and I need to create this same report with this system using SQL.
    Does anyone know how to compare data between two different dates and pull the ones that don't match? Your help will be GREATLY appreciated!
    Warm Regards,
    Yasmin E. Alberto
    HRIS Analyst
    [email protected]

    Hi, Yasmin,
    In the sample data you posted, nobody changed departments between May 1 and May 11. In fact, there were no assignments of any kind between January 16 and May 17, so I wouldn't expect any output for that period.
    A person (or rather, a duck) did change deptartments on May 20, so if you change the upper limit of the date range to
    AND    ASG_LAST_UPDATE_DATE < TO_DATE ('05/21/09', 'MM/DD/RR')you should see her.
    You've probably noticed that this site likes to compress white-space.
    To post formatted text (such as table results or indented code) type these 6 characters:
    (small letters only, inside curly brackets) before and after sections of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for

  • Purchase Order: Mass modifications

    Hello: I'm using transaction MEMASSPO to change "delivery date" in purchase orders but I can't. OSS note 443777 says it is possible to do that since: "... Transaction MEMASSPO can only change fields which are contained in the standard system of progr

  • Printing document.... images w/ transparent background print with visable border

    I created a document in adobe InDesign CS3. I've placed some graphic images that have transparent background onto the document. It looks fine on my PC but when I print on a laser color printer, it prints with a noticeable background on the image. Drv

  • How to reopen a closed connection?

    If I'm working on a worksheet, and I lose connection, how do I reopen it? I try running my code, and the Query Result just says "Closed Connection". The little connection dropdown list on the top-right corner of the screen gets grayed out when I lose

  • SUM STATEMENT

    HI GURU'S, Please can anybody explains me what is significance of using SUM statement inside the AT AND ENDAT statement. what i understood about sum is: The statement SUM calculates the component total with the numeric data type (i, p, f) of all rows

  • Apps update

    Hi! I'm unable to update apps in my new iTunes. I used to go to the "App" tab, and press "Download all updates available". It's not there anymore! How can I update my apps on the computer now? It takes longer to do that on my iPhone. Thanx!