Reg : subtracting weekoff day from the time difference

Hi ,
I have query where I am getting time difference first of all in terms of hours as:
DECLARE @L_TIME_DIFF   INT
SET @L_TIME_DIFF= (DATEDIFF(hh, '05/09/2014', '05/12/2014'))
i.e. subtracting 12th may - 9th may and getting diff in hours ..in this case it will be 3*24 = 72 hours
All fine till here. Now next step I need to subtract from this 72 hours if falling any week off day. It can be Friday, it can be Saturday, or Sunday, or Half day Saturday, or Half Day Sunday, or Full 2 days Saturday/Sunday  .
The above scenario is decided based on one table [CALENDER_WORKINGDAYS] which looks like below :
CAL_WORKING_DAY 
CAL_AM
CAL_PM
CAL_SEQ_NO
Monday
1
1
1
Tuesday
1
1
2
Wednesday
1
1
3
Thursday
1
1
4
Friday
0
0
5
Saturday
1
1
6
Sunday
1
1
7
So in this case, if you look at friday (CAL_AM=0 and CAL_PM=0) this measn friday full day holiday for some country.
Hence I need to : 72 - 24 = 48 Hours should be my output.
In another scenario, let s say some country work half day Saturday and Sunday full day off.
So my output should be : 72 - 36 (because 24 hours for sunday off, and 12 hours for saturday half day off) =
36 should be my output
and so on..
Can you help to build such query based on the above table given ?
Thanks

Hi Jose Diz,
I am trying the below logic. Seems it should be working:
DECLARE
@L_START_TIME    DATETIME,          
@L_END_TIME    DATETIME,
@L_TIME_DIFF   INT, -- Time Difference considering week offs          
@W_TIME_DIFF   INT ,-- Whole Time Difference,
@PUBLICHOLS   INT,
@WEEK_OFF INT
set @L_START_TIME    = '5/9/2014';
set @L_END_TIME    = '5/12/2014';
/* TO GET THE TIMDIFFERENCE */          
  SET @L_TIME_DIFF=(DATEDIFF(hh,@L_START_TIME,@L_END_TIME))          
  SET @W_TIME_DIFF = @L_TIME_DIFF          
-- Subtracting day off in the week(i.e. sat/sun or in some case friday) if it is in between start and end
  set @WEEK_OFF= 0;
    SELECT @WEEK_OFF= @WEEK_OFF + 12 * (abs(CAL_AM -1) + abs(CAL_PM -1))
    from CALENDER_WORKINGDAYS
 IF DATENAME(WK,@L_END_TIME) > DATENAME(WK,@L_START_TIME)           
 BEGIN          
  SET @L_TIME_DIFF= @L_TIME_DIFF - @WEEK_OFF          
 END          
Thanks to confirm

Similar Messages

  • How to subtract a day from the presentation variable @{system.currentTime}

    Hello,
    How can subtract a day from the presentation variable - @{system.currentTime}
    I use the above as a title in the report. However I want to subtract a day from the above variable. How can I accomplish it?
    Thanks.

    Hi,
    Did you try the steps which I mentioned above. You can use TIMESTAMPADD function in many places in your report but I think not in title section of the title view.
    Also you can try using Narrative view instead of title view to achieve this. Follow below steos:
    * Pull another column in the report and change its fx to TIMESTAMPADD(SQL_TSI_DAY, -1, @{system.currentTime})
    * Now go to the Narrative view and add the below text in Narrative section of the view.
    Active Person Report as of @1
    Here @1 assuming the new column created is placed before all the columns in the request.
    * Also set the 'Rows to Display' as 1.
    * Delete Title view from the report and this narrative view on top of your report.
    Hope this helps.
    Thanks

  • Reg: Excluding one day from the daily schedule process chain

    Hi All,
    I have a process chain scheduled daily except Sunday i.e. from Monday to Saturday. Now i want to exclude Saturday from the daily scheduling.
    Any idea how we can do that. Early response will be highly appreciated.
    Best regards

    Hi,
    Restrict chain Scheduling on Sundays/Holidays
    Create a factory calender using TCode SCAL or ask your basis team to create one.
    In this calender mark all days except the day you dont want the chain to run as workday.
    Now while scheduling the process chain make use of this calender and restrict it to run only on the workdays.
    There is a setting in the start process of the PC by which your chain wont run in sundays/holidays based on calendar or run only on workdays as defined in the factory calendar.
    Go to PC > start process > change selection  > Date/time. Here enter the date from which the chain should be scheduled and then click the Restrictions button at the bottom. There u can check the option "Dont execute job on sundays or holidays.
    Hope this helps.
    Thanks,
    JituK

  • Need to subtract one day from the date appearing

    Hi, I am modifying a script in such a way that for an output type there is an invoice date appearing.  This invoice date should be back dated to 1 date less to the actually date that is appearing currently.
    For ex the date is 2007.08.30 it should appear as 2007.08.29.
    While debugging I found that it is picking up the data for the date from the structure vbdkr and the field is fkdat. From the following code in the script.
    /:   DEFINE &SALES_ORDER& := &VBDKR-VBELN_VAUF&
    /:   INVOICE DATE,, : &VBDKR-FKDAT&
    What changes do I need to make the changes in the script or in the driver program?
    Can you please suggest?
    Thanks.

    Hi..
    You can get this Functionality by Calling a FORM (subroutine) from the Script Layout itself  There is no need to change the Print program.
    Eg:
    In the layout set -> window -> text elements. Write this before displaying invoice date
    /: PERFORM F_DATE_SUB IN PROGRAM ZPRG01
    /: CHANGING &VBDKR-FKDAT&
    /: ENDPERFORM
    INVOICE DATE,, : &VBDKR-FKDAT&
    Create the report program ZPRG01: In the program ZPRG01
    FORM F_DATE_SUB TABLES INTAB STRUCTURE ITCSY
                                                  OUTTAB STRUCTURE ITCSY.
    DATA: L_DATE TYPE D.
    READ TABLE OUTTAB INDEX 1.
    L_DATE = OUTTAB-VALUE. "you need to convert here
    SUBTRACT  1 FROM L_DATE.
    OUTTAB-VALUE = L_DATE.
    MODIFY OUTTAB INDEX 1.
    ENDFORM.
    reward if Helpful.

  • How to write a query to get the time difference of two varchar type time columns

    Hi,
    I want to get the time difference between the two varchar type columns.please see the attached image for more details:
    My requirement is like:
    timestarted
    timeended
    timediff
    9:00:00
    10:00:00
    1:00
    9:15
    9:30:00
    0:15

    Storing time alone as VARCHAR2 value is a incorrect design. Always store it as DATE or TIMESTAMP.
    If you already have a messed up design and cant change it, then you need to convert your VARCHAR2 time into a DATE or TIMESTAMP and find the difference. I have converted it to TIMESTAMP and obtained the difference as INTERVAL.
    SQL> with t
      2  as
      3  (
      4  select '09:00:00' timestarted, '10:00:00' timeended from dual
      5  union all
      6  select '09:15:00' timestarted, '09:30:00' timeended from dual
      7  )
      8  select timestarted
      9       , timeended
    10       , (timeended - timestarted) day to second diff
    11    from (
    12          select to_timestamp('01011900' || timeended, 'ddmmyyyyhh24:mi:ss') timeended
    13               , to_timestamp('01011900' || timestarted, 'ddmmyyyyhh24:mi:ss') timestarted
    14            from t
    15         );
    TIMESTARTED                                        TIMEENDED                                          DIFF
    01-JAN-00 09.00.00.000000000 AM                    01-JAN-00 10.00.00.000000000 AM                    +00 01:00:00.000000
    01-JAN-00 09.15.00.000000000 AM                    01-JAN-00 09.30.00.000000000 AM                    +00 00:15:00.000000
    SQL>

  • Get days from the java.util.date class

    Does anyone know how to get the days from the java.util.date
    class. I'm trying to subtract two dates to get the total days between
    the two dates. Any help would be appriciated
    Rob

    If you use the getTime() method, you get the date as a number of milliseconds since a predefined time. You can do arithmetic on that number, such as subtracting two of them to get the number of milliseconds between two Dates, and so on.

  • Subtract business days from date - calculated column

    Hello,
    I had a calculated column on a library that took two dates and found the difference between them in business days, but I am not sure how to subtract business days from a date...for instance I get a start date from a form and I need to
    subtract 10 business days from that date.
    Can anyone help?

    I've always resorted to Javascript/JQuery for that kind of function. I found an old fashioned loop worked the best for me - it supports going forward or backwards. I key it off of a change in a starting date, or sometimes a status change. My actual production
    code takes into account another list where we remove holidays and non-work days.
    newDate = getNextDate(newDate, -3);
    $("input[title='Date Due']").val((newDate.getMonth() + 1) + "/" + newDate.getDate() + "/" + newDate.getFullYear());
    function getNextDate(currentDate, offset) {
    // offset is business days
    var wkend = 0;
    var index = Math.abs(offset); // need positive number for looping
    var neg = true;
    if(offset >= 0) { neg = false; }
    var curDOW = currentDate.getDay();
    var nextDate = new Date(currentDate);
    for(var i=1; i <= index; i++) {
    nextDate.setDate(nextDate.getDate() + (neg ? -1: 1));
    var nextDOW = nextDate.getDay();
    if(nextDOW == 0) {nextDate.setDate(nextDate.getDate() + (neg ? -2: 1));} // Sunday
    if(nextDOW == 6) {nextDate.setDate(nextDate.getDate() + (neg ? -1: 2)); } // Sat
    // alert("offset is " + offset + "start: " + currentDate + ", next date is " + nextDate);
    return nextDate;
    Robin

  • How do i edit my billing info if my credit card associated with apple id expired and i have a duty to app store from the time when i had the old credit card?

    how do i edit my billing info if my credit card associated with apple id expired and i have a duty to app store from the time when i had the old credit card?
    so the thing is a few days ago i made an app store purchase and i didn't know i was running out of money on my credit card. i realized that only when i tried to purchase another item and it didn't work. nothing special til here. the problem is that meanwhile my credit card was replaced by a new one by the bank because the old one was soon expiring. So the data associated with the old credit card no longer exist.
    i tried to edit my billing info associated with my apple id in order to enter the new credit card data, but the system doesn't allow me to do that.
    so i can neither pay my purchase, nor edit my info, nor access app store anymore.
    what's next? any ideas? thanks

    Servers down wait till status is fixed to change or add your data http://www.apple.com/support/systemstatus/

  • Stopping a while loop using the time difference of two tick counts

    Hi Guys,
    I'm currently writing a code which test how long does it take for a formula node to perform its operation. The program uses a while loop to perform the calculation, and the program stops after calculating when tick count has reached 10 seconds. The program then displays the number of iterations it does in 10 seconds. 
    So initially I created 2 frames of sequence structure. In my first frame I have my initial tick count, and in my second frame I have my final tick count and the while loop. I used the subtract function and divide the output by 1000 to get the time difference. Then using the comparison function, I set if output > 10 then the program should stop, to do this I linked the output of the comparison function to the stop button inside the while loop. 
    However, when I tried to run the code, the program just didn't run. Hence I created a similar program which puts the last tick count in new frame sequence. When I ran this code, the program never stopped. 
    Do you guys have any idea what went wrong with my codes.
    Thank you!
    Erry
    Solved!
    Go to Solution.
    Attachments:
    1. Tick Count.vi ‏27 KB
    tickcoun2.vi ‏27 KB

    Dataflow!
    In both VI's the stop terminal of the while loop is controlled by a boolean whose source is ouside of the while loop.  So that loop will either run once, or run forever, depending on the value of the boolean that is calculated before the loop starts and shows up at the tunnel going into the loop.
    I would recommend looking at the online LabVIEW tutorials
    LabVIEW Introduction Course - Three Hours
    LabVIEW Introduction Course - Six Hours

  • From the time i upgraded to os lion my battery backup from 7 hours became 4 hours, how do i resolve it?

    from the time i upgraded to os lion my battery backup from 7 hours became 4 hours, how do i resolve it?

    When you upgrade to Lion, Spotlight will re-index your hard drive. This happens only once, but can take a while and may eat a lot of battery. Is still Spotlight indexing? If yes, then check your battery amount in the coming days after the indexing is complete. If Spotlight is done indexing, do the same and check it the coming days.

  • How to calculate the Time difference between 2 dates

    HI All,
    I am using HR_hk_diff_btw_2_dates to calculate the employee service dates.
    For that i  am inputing his hire date and Term dates and Output format as '05' i am getting output perfectly....
    But problem is  whe i am inputting the employee hire date is Dec 1 2007 and Term date is
    March 31 2009 It is coming as 1 year 3 months  31 days instead of 1 year 4 months directly .......How could we make it make last date also working day and get the O/p as 1 year 4 months ?Please Advice..
    Regard
    sas

    1. FM for difference betwwen two times:SCOV_TIME_DIFF
    Import parameters               Value
    IM_DATE1                        2008-01-01
    IM_DATE2                        2008-01-01
    IM_TIME1                        10:00:00
    IM_TIME2                        11:30:00
    Export parameters               Value
    EX_DAYS                         0
    EX_TIME                         01:30:00
    2. SD_CALC_DURATION_FROM_DATETIME : Finds the difference between two date/time and report the difference in hours
    L_MC_TIME_DIFFERENCE : Finds the time difference between two date/time

  • How to get the time difference (in seconds) between two timestamp fields?

    Hi All,
    I'm exploring validation expressions in SAP MDM Data Manager version 7.1.07.245
    I have two timestamp fields, suppose Update Date and Update-GDS.
    What I'm trying to do is prompt a warning when:
    (Update Date minus Update-GDS) is greater than or equal to zero seconds
    AND
    (Update Date minus Update-GDS) is less than or equal to 900 seconds
    the bottomline is, Update Date must be equal or greater than to Update-GDS but Update Date must not exceed 900 seconds difference.
    my initial try was:
    (Update Date - Update-GDS)>=0 s AND (Update Date - Update-GDS)<=900 s
    But it always returns true even the time difference between update date and update-gds is beyond the condition.
    Can you please guide me through this?
    Thank you very much in advance.
    Regards,
    ~erwin

    Hi Abhishek,
    I tried your code but it always returns true.
    It seems subtraction of timestamp fields do not actually get the time difference... (in seconds)
    Is this possible anyway? Or is there any other better approach on this?
    Thanks,
    ~erwin
    Edited by: erwin.j.rivera on Dec 14, 2011 8:40 AM

  • How to find the time difference..?

    HI
    How to find the time difference between two times
    for Example
    the difference between '24/10/2005 8:25:00 PM' and '25/10/2005 5:20:00 AM'
    is 8.55
    Kris

    This is a procedure taht do the job
    CREATE OR REPLACE FUNCTION Diff_Time
         LD$Date_Deb IN DATE DEFAULT SYSDATE
         ,LD$Date_Fin IN DATE DEFAULT SYSDATE
         ,LN$JJ       OUT PLS_INTEGER
         ,LN$HH       OUT PLS_INTEGER
         ,LN$MI       OUT PLS_INTEGER
         ,LN$SS       OUT PLS_INTEGER
      ) RETURN NUMBER
    IS
      dif   NUMBER ;
    BEGIN
      IF LD$Date_Fin < LD$Date_Deb THEN
         RETURN ( -1 ) ;
      END IF ;
      SELECT  LD$Date_Fin - LD$Date_Deb INTO dif  FROM dual ;
      SELECT  TRUNC ( LD$Date_Fin - LD$Date_Deb)  INTO LN$JJ  FROM dual ;
      SELECT  TRUNC ( (LD$Date_Fin - LD$Date_Deb) * 24) -  ( LN$JJ * 24 ) INTO LN$HH FROM dual ;
      SELECT  TRUNC ( (LD$Date_Fin - LD$Date_Deb) * 1440) - ( (LN$HH * 60) + ( LN$JJ * 1440) ) INTO LN$MI FROM dual ;
      SELECT  TRUNC ( (LD$Date_Fin - LD$Date_Deb) * 86400) - ( (LN$MI * 60) + (LN$HH * 3600) + ( LN$JJ * 3600 * 24 ) ) INTO LN$SS FROM dual ;
      RETURN( dif ) ;
    END ;
    /You may have to modify it to fit your own requirement.
    Francois

  • How can I safe my data back from the Time capsule to iphone and macbook?

    Hi,
    last weekend we were robbed while being on vacation and iphones and macbook air got stolen. Good thing was that at home we had a time capsule and our normal macbook. As soon as we get the new iphones and the new airbook we want to get our itunes and apps and datas back to the iphones and airbook ... can somebody tell us how to re-safe or back-safe stuff from the time capsule back to the equipment?
    Thank you ... I feel so "naked" without my phone :-(
    Virtualkate

    Sorry about your loss. Follow the directions here to use Time Capsule to restore your new Air to the state your old Air was in when stolen. When you first connect your new phones, you'll be given the option of restoring from the backup of your old phones or setting up as new. Restore from your previous backups, followed by syncing your content back to your phones. You should be good to go. Maintaining current backups makes this a piece of cake.
    http://support.apple.com/kb/HT1177

  • How do I access my back up files from the time machine if my computer was stolen?

    Hi, how do I access my back up files from the time machine if my mac book pro was stolen? I have a mac book air and mac too. But not sure how I can get back all the files from the stolen computer from my time capsule

    On the Mac Book Air or other Mac that you have, use Migration Assistant to transfer files from the Time Machine backups of the Mac that was taken.
    Macintosh HD > Applications > Utilities > Migration Assistant

Maybe you are looking for