Time Passage Calculation excluding Weekends and Non-work hours

Good Afternoon Everyone!
I am currently using the expression below to determine the amount of time that has passed since a Task has been created.
TIMESTAMPDIFF(SQL_TSI_MINUTE, Activity."Created Date", NOW())
We have a completion goal for a specific task type of 2 hours (120 minutes), but it should only be calculated minutes between 7 AM and 4 PM and only on week days.
So, a task created at 3:50 PM on a Friday that is completed at 7:30 AM on the following Monday should only calculate to 40 minutes of time.
I am at a loss for where to start tackling this problem. If any of you can help I would be very appreciative!

Hey Paul, thanks for the prompt. I see now that the formula is incomplete.
As I have just taken the difference in days between the Activity Start Time and End Time, it will consider any weekend. But its incomplete as it considers only 15 hours of a day and not the remaining 9 hours for weekends. For holidays - we do need a field or something to identify it like Activity Type = 'holiday'.
So the ELSE* part of revised formula would be something like this:
... ELSE TIMESTAMPDIFF(SQL_TSI_MIN,activity start time,activity end time) - (60*15*(DAY(Activity End Time) - DAY(Activity Start Time))) - (60*9*(COUNT(DISTINCT CASE WHEN DAYOFWEEEK(Date.Date) IN (6,7) OR ~some field to identify holiday~ = 'something' THEN 1 END)) END
now imagine there's one activity that started on Friday 7:00 AM and ends on coming Monday at 4:00 PM.
Actual duration is 18 hours.
Now,the first term after ELSE will give 81*60 minutes. next term should give 45*60 minutes. third term would be 18*60 min.
so the entire expression would return 18 hours.
Even if there's a holiday, then i guess the 'OR' part should capture it.
I hope this makes sense. Please let me know if it should need any further corrections.

Similar Messages

  • Calculate Date/Time Difference in a Calculated Column Omitting Weekends, Holidays and Non-Working Hours

    I am looking for a formula to use in a calculated column that calculates the difference between two date/time fields while excluding weekends, holidays and non-working hours
    6/1/2010 9:43 AM - 6/7/2010 1:45 PM
    Here is the closest that I have gotten; however, this formula gives me a result of 96:
    =IF(AND((WEEKDAY([Resolved Date],2))<(WEEKDAY(Created,2)),((WEEKDAY(Created,2))-(WEEKDAY([Resolved Date],2)))>1),(((DATEDIF(Created,[Resolved Date],"D")))-(FLOOR((DATEDIF(Created,[Resolved Date],"D")+1)/7,1))-3),(((DATEDIF(Created,[Resolved Date],"D")))-(FLOOR((DATEDIF(Created,[Resolved
    Date],"D")+1)/7,1)*2))*24)
    Any and all assistance is greatly appreciated!

    I don't know how to exclude holidays but i exclude weekends(Sat&Sun)-
    IF(ISERROR(DATEDIF([Start Date],[End Date],”d”)),””,(DATEDIF([Start Date],[End Date],”d”))+1-INT(DATEDIF([Start Date],[End Date],”d”)/7)*2-IF((WEEKDAY([End Date])-WEEKDAY([Start
    Date]))<0,2,0)-IF(OR(AND(WEEKDAY([End Date])=7,WEEKDAY([Start Date])=7),AND(WEEKDAY([End Date])=1,WEEKDAY([Start Date])=1)),1,0)-IF(AND(WEEKDAY([Start Date])=1,(WEEKDAY([End Date])-WEEKDAY([Start Date]))>0),1,0)-IF(AND(NOT(WEEKDAY([Start Date])=7),WEEKDAY([End
    Date])=7),1,0))
    -Thanks
    Swapnil

  • 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

  • SLA Calculation needed to exclude Holidays, Weekends and Off business hours

    Hello all,
    I am to create a function that will calculate the minutes between two dates for company work hours, excluding the weekends. 
    The function here from RSingh() is ideal for this purpose; however I am now asked to excluded company holidays also.
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/de4f7661-c702-4a10-ad06-3e28e4e0a83c/sla-calculation-help-needed-in-excluding-weekends-and-off-business-hours-for-calculation?forum=transactsql
    With a table called 'holidays' that contains holiday dates. I would hope to modify the function to exclude these.
    Please, how can this be accomplished? 

    My approach would be something like this
    Populate a calendar table that includes a work start and work end time for each day (none for weekends and holidays)
    SELECT *
    INTO #cal
    FROM (
        SELECT CAST('20140117' AS DATE) AS CalendarDate
            , CAST('20140117 09:00' AS DATETIME) WorkStart
            , CAST('20140117 17:00' AS DATETIME) AS WorkEnd
        UNION ALL
        SELECT CAST('20140118' AS DATE) AS CalendarDate
            , CAST(NULL AS DATETIME) WorkStart
            , CAST(NULL AS TIME) AS WorkEnd
        UNION ALL
        SELECT CAST('20140119' AS DATE) AS CalendarDate
            , CAST('20140119 09:00' AS DATETIME) WorkStart
            , CAST('20140119 17:00' AS DATETIME) AS WorkEnd
        UNION ALL
        SELECT CAST('20140120' AS DATE) AS CalendarDate
            , CAST(NULL AS DATETIME) WorkStart
            , CAST(NULL AS TIME) AS WorkEnd
        UNION ALL
        SELECT CAST('20140121' AS DATE) AS CalendarDate
            , CAST(NULL AS DATETIME) WorkStart
            , CAST(NULL AS TIME) AS WorkEnd
        UNION ALL
        SELECT CAST('20140122' AS DATE) AS CalendarDate
            , CAST('20140122 09:00' AS DATETIME) WorkStart
            , CAST('20140122 17:00' AS DATETIME) AS WorkEnd
        ) X
    Use a query something like the following to work out the number of minutes
    DECLARE @Start DATETIME = '20140117 13:00'
    DECLARE @End DATETIME = '20140122 17:00'
    SELECT SUM(diff)
    FROM (
    SELECT DATEDIFF(MINUTE, CASE WHEN CAST(@Start AS DATE) = CalendarDate
    AND @Start > WorkStart THEN @Start ELSE WorkStart END, CASE WHEN CAST(@End AS DATE) = CalendarDate
    AND @End < WorkEnd THEN @End ELSE WorkEnd END) AS diff
    FROM #cal
    WHERE CalendarDate BETWEEN CAST(@Start AS DATE)
    AND CAST(@End AS DATE)
    ) X
    Edit: Totally mucked up the example calendar table so I've changed it

  • Add working days to a date excluding weekends and holidays

    Hi there,
    I need to write a function that will take a specified date and number of days to add as input parameters, and return the working day based on the number of days to add parameter, excluding weekends and any holidays held in a holiday table.
    Here is my function so far -
    CREATE OR REPLACE FUNCTION f_add_work_days(pd_date IN DATE
    ,pn_add_days IN PLS_INTEGER) RETURN DATE IS
    pd_in_date DATE := pd_date;
    ld_next_holiday DATE;
    ln_days_left PLS_INTEGER := pn_add_days;
    CURSOR cu_holiday(pn_date IN ge740.holdte%TYPE) IS
    SELECT pck_utility.f_dtcnv(g.holdte)
    FROM ge740 g
    WHERE g.holdte >= pn_date
    AND g.maint <> 'D'
    ORDER BY g.holdte ASC;
    BEGIN
    OPEN cu_holiday(pck_utility.f_dtcnv(pd_in_date));
    FETCH cu_holiday
    INTO ld_next_holiday;
    CLOSE cu_holiday;
    LOOP
    IF ln_days_left = 0 THEN
    EXIT;
    END IF;
    pd_in_date := pd_in_date + 1;
    IF pd_in_date > ld_next_holiday THEN
    OPEN cu_holiday(pck_utility.f_dtcnv(pd_in_date));
    FETCH cu_holiday
    INTO ld_next_holiday;
    CLOSE cu_holiday;
    END IF;
    CASE
    WHEN TO_CHAR(pd_in_date
    ,'fmDAY') = 'SATURDAY' THEN
    pd_in_date := pd_in_date + 2;
    ln_days_left := ln_days_left - 1;
    WHEN TO_CHAR(pd_in_date
    ,'fmDAY') = 'SUNDAY' THEN
    pd_in_date := pd_in_date + 1;
    ln_days_left := ln_days_left - 1;
    WHEN pd_in_date = ld_next_holiday THEN
    pd_in_date := pd_in_date + 1;
    ln_days_left := ln_days_left - 1;
    ELSE
    ln_days_left := ln_days_left - 1;
    END CASE;
    END LOOP;
    RETURN(pd_in_date);
    END f_add_work_days;
    I think there is something wrong/missing in the logic as I can't get it to cater for say a double bank holiday(25/26th Dec - if the input parameters are 24/12/2007 and 2, which should return the 28th but returns the 26th!!).
    I'm relatively new to PL/SQL and Oracle, so any help, advice, ideas would be greatly appreciated!
    thanks in advance

    smth like
    SQL> with holidays as (select to_date('10.06.2007','dd.mm.yyyy') h_dt from dual),
      2       par as (select to_date('08.06.2007','dd.mm.yyyy') dt, 2 add_days from dual)
      3  --
      4  select min(dt) needed_date
      5    from (select p.*,
      6                 h.*,
      7                 mod(to_char(dt, 'j'), 7),
      8                 sum(decode(mod(to_char(dt, 'j'), 7), 5, 0, 6, 0, 1)+--get rid of sat and sun
      9                     nvl2(h_dt, -1, 0)--check if the day is holiday
    10                     ) over(order by dt) s
    11            from (select dt + level dt, add_days
    12                    from par
    13                  connect by level <= 100) p,
    14                 holidays h
    15           where h_dt(+) = dt
    16           order by 1)
    17   where add_days = s
    18  /
    NEEDED_DATE
    13.06.2007
    SQL> ?
    Message was edited by:
    Volder
    PS What Oracle version are you on?

  • Working day formula that excludes weekends and holidays in WEBI

    Hi Guys,
    Can we calculate a working day formula that excludes weekends and holidays in WEBI OR in Universe?
    The universe I am working on is using stored procedures, so there are no joins or modelling done. Although there is a workday stored proc  that I can bring in the universe.
    I am just thinking if there is no modelling or joins done in the universe how will this help me in webi?
    Your suggestions will be very helpful.
    Thanks,
    Jitan

    One more suggestion I need from you  -
    I have a Work_Calendar_VW that has the following columns -
    Calendar_Date - 5/1/2014
    Calendar_Year - 2014
    Calendar_Month - 5
    Calendar_Day - 1
    Work_Day - 1
    Day_Type - WD (Work Day)  For Weekends this will be displayed as WE
    The columns have all dates for current year in SQL Server.
    I am going to pull this into the universe and create 2 derived tables to calculate MTD Day counts.
    Derived Table 1  - Calculate Yest Work Day... this will remove all the weekends and holidays and give me the last working day. This includes couple of case statments to check each day if it's a working day or weekend.
    For Work Day the above code will be 1 and for weekend 0
    Derived Table 2  - This will give me the count of working days in current month using the above view and Derived table 1 Below is the code  -
    SELECT COUNT(*)
    FROM Work_Calendar_VW
    WHERE [Work_Day] = 1 AND
       (Calendar_Date BETWEEN CAST(CONVERT(VARCHAR(25),MONTH(LastWoringkday()),101) + '/01/'
       + CONVERT(VARCHAR(25),YEAR(LastWoringkday()),101) AS DATE)
      AND LastWoringkday()).
    I cannot do joins because this universe has been built using stored proc and would like to implement this in BO universe.
    let me know if this is the right approach.
    Thanks,
    Jitan

  • Resource availability during Non-Working Hours and Weekends

    Hi Gurus,
    Aim: Make the Resource available during Non-Working Hours and Weekends
    Requirement: CRP functionality enabling
    In CRC2 I have selected capacity tab and in capacity header under 'Change Interval and Shifts' button. I have Inserted a new Interval period and given the validity from/to dates(Non-Working day - Saturday) and Saved.
    When i execute the Capacity Planning CM01, there is no change. The Resource availability still shows as "0"hrs for this particular date and for rest of the days it shows as 8hrs.
    I have checked the same even after executing the MRP, No change in Capacity Planning Overview - Still the available Capacity Showas as 0
    Please guide me, how can i use my resource during the holidays. Means make the system understand that the defined day is a working day though it is holiday as per factory calendar
    Please correct me whether am i missing any settings or i should follow some other logic
    Regards,
    Tam

    Hi Partha,
    In workdays i dont have any such option "2"
    As per standard list I could see only 3 entries in the possible values(F4) popup
    "Blank" - Working days according to factory calendar
    "0" - Non-Working days(Overrides factory Calendar)
    "1" - orking days(Overrides factory Calendar)
    I have even tried with option "0" and "1" its still the same, when i enter the period From and To date the fields for the entries Shift start and end date, workday, Shift Seq, Length of the shift, No.of shifts.........are jumping to the next line item.
    Because of which i understand that the entered values is not corresponds to the newly defined period
    Pls guide me to how to make the resource available during non working days
    Regards,
    TamNen

  • Whenever I go to iTunes with my iPod 5th generation 32 gb iPod Touch, running iOS 8.0.2, It tells me that the "Other" category is using up 14.59 gb of data. I have no clue why it says this and I have searched the internet for fixes and none worked.

    Whenever I go to iTunes with my iPod 5th generation 32 gb iPod Touch, running iOS 8.0.2, It tells me that the "Other" category is using up 14.59 gb of data. I have no clue why it says this and I have searched the internet for fixes and none worked. I have tried on a windows and a mac and noticed no change. I have tried restoring to a backup but that didn't help. I haven't had time to do a full restore but I will try if the problem persists.

    An "other" larger than about 1 1/2 GB indicates corrupted files.
    What is the Other on my iPhone and How to Remove It
    What is "Other" and What Can I Do About It?
    Next, usually restoring from backup eliminated the corrupted files. However, sometimes restoring to factory settings/new iPod is required.
    To restore from backup see:
    iOS: How to back up
    To restore to factory settings/new iPod see:
    iTunes: Restoring iOS software

  • DATEADD excluding weekends and holidays

    select getdate(),dateadd(day,15,Getdate())
    THis gets me today and 15 days from now. However I need 15 business days. I need to exclude weekends and holidays in here so that is looks like this. 
    where fulldate between getdate() and dateadd(day,15,Getdate())
    I have a dim table for dates and have an isholiday = 0 or 1. I just can't figure out how to include this in the DATEADD expression.

    Hi,
    try this link
    http://www.sqlservercentral.com/Forums/Topic1247790-391-1.aspx
    Hope will help you,
    Questo post è fornito &quot;così com'è&quot;. Non conferisce garanzie o diritti di alcun tipo. Ricorda di usare la funzione &quot;segna come risposta&quot; per i post che ti hanno aiutato a risolvere il problema e &quot;deseleziona
    come risposta&quot; quando le risposte segnate non sono effettivamente utili. Questo è particolarmente utile per altri utenti che leggono il thread, alla ricerca di soluzioni a problemi similari. ENG: This posting is provided &quot;AS IS&quot;
    with no warranties, and confers no rights. Please remember to click &quot;Mark as Answer&quot; on the post that helps you, and to click &quot;Unmark as Answer&quot; if a marked post does not actually answer your question. Please Vote This As
    Helpful if it helps to solve your issue. This can be beneficial to other community members reading the thread.

  • Completely frustrated with downloan not working and deleting and attempting to reinstall resulting in three different accounts on my computer and none working.

    I downloaded Firefox mobile to my Droid. Connected to computer and followed instructions, using code provided on phone. Did not work. I tried to re-sync phone. It didn't work. I deleted Firefox on phone and reinstalled app. The connected phone to computer to re-sync. Could not get anything to work using"I have an account" tab so opened up another sync account. It didn't work. I deleted app again and tried again and used a third sync account to sync phone with computer. I got nowhere. Completely frustrated with three sync accounts and none working.
    Need help to delete all accounts and start over. Can't seem to find a way to do this.
    Thanks in advance.
    Bill

    Colin,
    I tried this (opening in Photoshop CS5 and resaving as jpg) as you mention:
    The remedy to this problem has usually been to open the image (the one that is having an identity crisis) in Photoshop or another image editor, and simply resave it. You don't need to edit it or rename it or anything--just open and resave.
    Re-imported and it does work fix (I get picture1 and picture2 instead of  just picture1 for all pictures).
    Having said that, I looked at all the file properties I could for:
    picture1.jpg (original)
    picture1.jpg (resaved in CS5)
    To see what changed. All are properties are identical (color depth, pixel size, etc.) except that resaved image is ~20% larger (I saved max file size jpg in CS5).
    So original is ~6MB
    resaved jpg is ~8MB
    So the question - why can't CS5 premiere import these directly (with resaving?) and what is working with the resave that locks up the first time?
    These pictures are straight from a Canon 50D, with no editing or resaving - dumped off camera to computer.  I can reproduce this error 100% of the time (new project, new folder, import 2 pics) so it isn't something goofy with the way I'm importing - 100% how premiere is handling this.
    Very disappointed that I now need to open/resave/rerender each of ~1100 images to simply use them.  Given that these jpgs are being produced by a mainstream camera with support image format.
    Any thoughts?

  • Changing working and non-working days

    Hi
    I am trying to make a permanent (default) change in working and non-working days. I am living in Israel and our non-working days are friday and saturday. I want to configure these as the non-working days so I won't need to do it manually via the change work
    time menu.
    Thanks
    Chen

    If you are using project server then you can do it permanent from 
    PWA --> Server Settings --> Enterprise Data --> Enterprise  Calendar then
    You can configure either your stranded calendar or create a new calendar in which you can make Sunday to Thursday as working days and Friday and Saturday as non working days.
    You have to do it manually. There is no tool available which will do the same for you.
    Where as if you are using Microsoft Project professional stand alone then for every plan (MPP file) you have to do it.
    kirtesh

  • Licensing has stopped working - I tried all the published options and none work. Acrobat 9 Pro Mac Air 10.9.5

    Licensing has stopped working - I tried all the published options and none work. Acrobat 9 Pro Mac Air 10.9.5
    Thank you for your help

    Hey,
    Considering error "licensing has stopped working", you might need to try out the solutions mentioned in the following KB doc link:
    Error "Licensing has stopped working" | Mac OS
    Let me know if this helps.
    Regards,
    Anubha

  • Is my iPhone 4 greyed out wifi and non working bluetooth software or hardware... seems that the forums are full of this issue with no consistent or official answer. is it all coincidence that so many are having the problem? Please help...

    Is my iPhone 4 greyed out wifi and non working bluetooth software or hardware... seems that the forums are full of this issue with no consistent or official answer. is it all coincidence that so many are having the problem? Please help... I have scoured the net trying everything the last few days.

    Please correct your porfile: iPhone 4 do not have IOS 6.1.4.
    The usual troubleshooting steps are, also remember to test it after every step:
    1. Restart
    2. Reset
    3. Restore from backup
    4. Restore as new.
    If no joy, make an Appointment with the Apple genius and have them evaluate

  • HT3310 I have an iphone 5. Speaker works but I cannot hear through the apple earbuds. Tried multiple earbuds and none work. But they work in other iphone 5.

    I have an iphone 5. Speaker works but I cannot hear through the apple earbuds. Tried multiple earbuds and none work. But they work in our other iphone 5.  Has anyone been able to resolve this without pursuing a replacement ?  If so what was the fix?

    You're not using a supported carrier. What did you think Apple was going to tell you?
    As fizzDripper suggests, contact the SIM card provider. How to make an unsupported SIM work on your phone is not Apple's problem.

  • Some programs do not run: update software, mac App Store, Calendar, ibooks.V the same time, the program iTunes, iPhoto and other work normally. What to do?

    Some programs do not run: update software, mac App Store, Calendar, ibooks.V the same time, the program iTunes, iPhoto and other work normally. What to do?

    Hello JohnnyChin95,
    You absolutely can just reinstall OS X Mavericks without having to erase and install. The steps to do that are almost the same as the only thing you do differently is that you do not go to Disk Utility to erase the drive. Just go to the Reinstall OS X option and pick your Hard Drive and follow the on screen instructions to get it going. Check out the article below for the step by step process. 
    OS X Mavericks: Reinstall OS X
    http://support.apple.com/kb/PH13871
    Regards,
    -Norm G.  

Maybe you are looking for