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

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

  • Finding Day from Date i.e. Monday, Tuesday etc

    Hi,
    I need to find out the day from Date. i.e. Monday, Tuesday etc. This is because if the date falls on Saturday or Sunday need to charge difference rates and on weekdays having normal rates.
    Thanks,
    Amol

    We should probably add a function for this as I've certainly seen the requirement before.
    Fortunately it's pretty easy to calculate using a simple rule - the trick is to pick a date in the past that was a Monday, and then use the modulo operator.
    For example:
    The day of the week = (the given date - 1980-01-07) modulo 7
    ie the 7th of January 1980 was a Monday, so every 7th day after that is also a Monday - so combined with the modulo operator this will give you:
    0 monday
    1 tuesday
    5 saturday
    6 sunday
    The only downside is that dates before 1980-01-07 will give a negative modulo (this is distinct from the mathematical modulo operator, but is necessary to be symmetric with the integer division operator truncating towards zero) - so dates before the baseline date will give:
    0 monday
    -6 tuesday
    -2 saturday
    -1 sunday
    You can either choose to write the rules to take this into account, or choose a baseline date so far in the past that it's unnecessary.
    Regards
    Andrew

  • Oarcle Lite cannot subtract negative numbers from date

    Hello
    we have a very strange problem. We have a query that need to convert times between different timezones. So, we have
    In Oracle lite, the query
    select sysdate - (-60/1440) nd from dual returns sysdate + 2 - 60/1440.
    Whenever a negative fraction is subtracted from date, it always adds two days and then adds the fraction. Looks like negative of a negative fraction is not handled correctly in oracle lite.
    Did anyone encounter this problem? We have the system in production and wondering if anyone found a solution.
    Thanks

    HI sd,
    I suspect there's a simpler way, but this works, as seen in the example. Start and finish times are both incremented by one day as the data and formula are filled down the columns to show the effect of crossing the weekend days. Formula (as it appears in row 7) is shown above the table. The Row 2 version is copied below. Cels in column D are formatted as shown in the Inspector.
    D2: =NETWORKDAYS(B2,C2,)+DURATION(,,24*(DUR2DAYS(C2-B2)-INT(DUR2DAYS(C2-B2))),,,)
    Regards,
    Barry

  • Problem with binding value on the UI  from a calculated column in the view

    I have calculated field "Readiness" in my db view, which gets calculated based on other columns in the same table. I have added new column to my EO using "Add from table" option and added the same column from to VO using "Add from EO" option. In my application, I will update a particular date field in the UI and this calculated column "Readiness" in the db will be set to yes or no and this logic is working fine, both date date field and calculated field are in same view object. I have added a attribute binding to this "Readiness" column in my view page. The problem is the calculated column value does not reflect the new value in the db, it shows the old value. I have tried different refresh option for the iterator and ppr option for the field binding. Even after reloading the page, the value shown on the UI page is different from the value in db, other bindings on the UI page works fine, not sure any special settings are required for the Calculated columns. any ideas are appreciated.
    Thanks for your help,
    Surya

    I tried to add soms debugging statements in the EO and getters method, the calcaulated column is not picking the value in db view. I'm not any special iterator/field settings are required at BC level. I'm a newbie, any help is appreciated.
    Thanks,
    Surya

  • Add number of business days to date field

    Hello, I noticed that there is not much discussion in the forum surrounding u201Cbusiness daysu201D so I hope this post/discussion/solution contributes to the content of this forum.
    I am using the following 3 formulas to try to Add number of business days (based upon a table field) to a specified date:
    1. Variable name = SetVar
    //Set Variable for Add Business Days:
    DateVar Array Holidays;
    DateVar Target:= CDate({TMS_MOVEMENT_EVT.EVT_DATE}); // Put your field name in here
    NumberVar Add:=  {DTCI_DOD_TRANS.TRANS}; // put the number of days here to add (a positive number)
    NumberVar Added := (0);
    2. Variable name = AddBizDays
    //Adding Business Days:
    EvaluateAfter({@SetVar});
    WHILE Added < Add
    Do (target := target +1;
        if dayofweek (target) in 2 to 6 and not (target in holidays)
            then Added:=Added+1
            else Added:=Added);
    Target
    3. Variable name = HOLIDAYS
    //Holiday Array Formula for the report Header:
    BeforeReadingRecords;
    DateVar Array Holidays := [
    Date (2003,12,25),   // you can put in as many lines for holidays as you want. 
    Date (2003,12,31)
    0
    I am successfully getting my data needed to make the necessary calculations and variable assignmentsu2026 I believe that my ISSUE is that I am not sure where to place these formulas into my report so they assign the variables and execute properly when previewing my report. I am curious if that is my issue, and if so, can someone provide me direction on where to put each of these formulas in my report.
    Currently, when I try to preview the report, I get the following Crystal Reports Error:  -u201CA number, currency amount, Boolean, date, time, date-time, or string is expected here.u201D
    Then Crystal automatically opens the AddBizDays formula and highlights the word added, see below RE: u201CWHILE Addedu201D
    For reference, my report has 3 groups, and I am displaying all of my output information (and locating my formulas) in the group footer #3 report section. I have moved them around to other report sections/groups/placements, but to no success.
    Thanks so much.
    Best, Matt

    I worked this out... FYI - for the benefit of all forum users:
    ADDING BUSINESS DAYS TO A CERTAIN DATE (excluding weekends and holidays)
    1. Variable name = AddBizDays
    //Adding Business Days:
    WhileReadingRecords;
    DateVar Array Holidays;
    DateVar Target:= CDate(); // Put your field name in here
    NumberVar Add:=  ; // put the number of days here to add (a positive number)
    NumberVar Added := (0);
    WHILE Added < Add
    Do (target := target +1;
        if dayofweek (target) in 2 to 6 and not (target in holidays)
            then Added:=Added+1
            else Added:=Added);
    Target
    2. Variable name = HOLIDAYS
    //Holiday Array Formula for the report Header:
    BeforeReadingRecords;
    DateVar Array Holidays := [
    Date (2003,12,25), // you can put in as many lines for holidays as you want.
    Date (2003,12,31)
    0
    ...too bad i don't get forum points for sharing this solution.
    Special thanks to KenHamady.com -- for sharing this solution.
    Sincerely,
    Matt

  • How to create Remainder email workflow in share point 2010 designer without creating the remainder date (calculated) column in the list

    Hi,<o:p></o:p>
    I have task to create remainder email notification 3 days before by comparing with End
    date (my list item) so i created one calculated column in the list as remainder date by using that remainder date
    i created, but my project manager told me create same remainder notification work flow without create that remainder date i tried to write calculation in work flow
    but it is not working if any one knows how to do this please help me<o:p></o:p>
    Thanking you,<o:p></o:p>
    ArunDarly <o:p></o:p>

    Hi,
    For reminder type requirements, I tend to use the ‘Information Management Policy’ SPD method as described in
    this blog article by Laura Rogers (it’s for MOSS and WSS but works in SP2010 also).
    This method avoids the use of calculated columns; rather the workflow does the calculation and outputs information into a ‘reminder’ field. Also, I don’t like the idea of ‘paused workflows’, so this method works for me.
    Cheers
    Matt

  • Extrating day from date

    Hi All,
    Extracting day form sysdate is <?xdoxslt:sysdate(‘Day’)?>
    but i want to extract day from <?xdoxslt:ora_format_date_offset(xdoxslt:sysdate('YYYY-MM-DD'),1,'-')?> (sysdate-1 date's day)
    How can i ? any ideas pleae share me.
    Thanks

    DD is working fine
    <?xdoxslt:xdo_format_date($_XDOXSLTCTX,(xdoxslt:ora_format_date_offset(xdoxslt:sysdate('YYYY-MM-DD'),1,'-')),’DD’)?>
    Day and Dy is not working giving result like check boxes
    <?xdoxslt:xdo_format_date($_XDOXSLTCTX,(xdoxslt:ora_format_date_offset(xdoxslt:sysdate('YYYY-MM-DD'),1,'-')),’Day’)?>
    do i need to give any supporting format for xdo_format_date?

  • 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.

  • Year , Month & Day from Date.

    Hi HANA experts,
      Do help me to resolve this issue
    How can we extract or fetch year from the date.i went through some of the SCN blogs.where they create calculation views...but the steps are not that clear to me.
    can anyone please explain??
    My scenario is :
    I have date field in ANALYTIC VIEW which i have fetched from ECC  tables.
    now i need to get  the year  wise month wise and day wise reports. so what steps i should do in calculation view to get that??
    thanks
    Neeraja

    there is no ECC under SAP...as we are using suite on HANA fro AWS.and there is no restriction done by the basis till now...
    as we are new to these unable to trouble shoot things easily.
    thanks for your reply..

  • Create a new dimension in business layer from Data source: text file on the web

    Hi,
    I have a text data source which is published every few hours that is accessible from a certain URL. I follow the instruction given in this http://scn.sap.com/docs/DOC-43144 - where it shows in great detail how to create the connection, data foundation as well as business layer to create a universe for this type of data.
    All is well - I can use this universe in my WEBI doc and display the data.
    However, in order for me to merge the data from this universe with another universe, I need to create  new dimension based on the data from the text file. The new dimension value is simply the first 4 characters of the Subject found in the text file. The "Subject" dimension is of variant type: varchar.
    Following the guide mentioned earlier, the connection is using SAP BO OpenConnectivity driver. And this driver limits severely the SQL statement that I can use to extract a substring of another string. Here's the screenshot of the SQl expression that I can use with this driver
    After hours of searching, I cannot find any other connection driver for a text file that's published on a certain URL. The BO OpenConnection driver is the best that I could find.
    So here are my problems
    1. one of my data source is a text file published on a web
    2. the only connection I can create does not allow me to create  new dimension in the universe to create an important column "subject ID"
    3. I can create the column in webi as a variable. But when I do so, I cannot merge it with existing dimension (webi not allowing to merge these 2 types). And without the merge, the flat file universe with my database universe can't be combined.
    I'm using WEBI Rich client version 4.1 SP3 Patch 1. Build 14.1.3.1300
    Is there any other idea that you can suggest without requiring to change the extracted data?
    Thanks.
    With warm regards

    Hi Bala,
    Were you able to find out a solution for the problem with uploading values for a variable from a text file on the web?  I am confronted with the same request from users.
    Thanks,
    BQ

  • Subtracting two rows from the same column

    Hi,
    I have the following table with about 6000 rows of different year_month but I am compare and subtract v
    Organization     Year_month     Contribution
    Kano     JAN-2011     200000
    KADUNA     JAN-2011     300000
    ABUJA     JAN-2011     400000
    Kano     FEB-2011     300000
    KADUNA     FEB-2011     200000
    ABUJA     FEB-2012     600000
    I want to select a year_month at run time to subtract the contribution of the first year_month from the contribution of the second year_month and give me the result as shown in the following table
    Organization     JAN-2011     FEB-2011     diffrence
    Kano     200000     300000     -100000
    KADUNA     300000     200000     100000
    ABUJA     400000     600000     -200000
    Here is my code returning too many va
    create or replace function "GET_MONTHLY_VALUE"
    (q_name in VARCHAR2,
    hmoCode in VARCHAR2)
    return VARCHAR2
    is
    c1 number;
    begin
    select NHIS_CONTRIBUTION into c1 from CONTRIBUTION_MGT where upper(YEAR_MONTH)=upper(q_name) and upper(ORGANIZATION)=upper(hmoCode);
    return c1;
    exception when NO_DATA_FOUND THEN
    return null;
    end;
    ------a call to the above function:
    create or replace function process_cont_monthly return varchar
    is
    Cursor cont_cursor is select ORGANIZATION from CONTRIBUTION_MGT;
    begin
    for
    cont_rec in cont_cursor loop
    select GET_MONTHLY_VALUE(:p26_month,cont_rec.ORGANIZATION) first, GET_MONTHLY_VALUE(:p26_month2,cont_rec.ORGANIZATION) second,
    abs(GET_MONTHLY_VALUE(:p26_month,cont_rec.ORGANIZATION)-GET_MONTHLY_VALUE(:p26_month2,cont_rec.ORGANIZATION)) Diffrence
    from CONTRIBUTION_MGT;
    end loop;
    commit;
    end;
    I became totally confused and don’t know what to do next
    Any help and better guide is appreciated

    Hi,
    Here's one way:
    WITH    months_wanted     AS
         SELECT     1 AS col, TO_DATE ('JAN-2011', 'MON-YYYY') AS month     FROM dual     
        UNION ALL
         SELECT     2 AS col, TO_DATE ('FEB-2011', 'MON-YYYY') AS month     FROM dual     
    ,     pivoted_data     AS
         SELECT       c.organization
         ,       NVL (SUM (CASE WHEN m.col = 1 THEN c.contribution END), 0)     AS total_1
         ,       NVL (SUM (CASE WHEN m.col = 2 THEN c.contribution END), 0)     AS total_2
         FROM       months_wanted     m
         JOIN       contribution_mgt  c ON  c.year_month >=            m.month
                                     AND c.year_month < ADD_MONTHS (m.month, 1)
    SELECT    organization
    ,       total_1
    ,       total_2
    ,       total_1 - total_2     AS difference
    FROM       pivoted_data
    ORDER BY  organization
    ;I assume that the year_month column is a DATE. Date information always belongs in DATE columns.
    As written, the two months do not need to be consecutive. If you always want consectuive months, this can be re-written so that you only have to enter the first month, not both of them.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Point out a few places where the query above is giving the wrong results, and explain, using specific examples, how you get those results from that data in those places. If you changed the query at all, post your code.
    Always say which version of Oracle you're using.
    See the forum FAQ {message:id=9360002}

  • Group by month/year from DATE FORMAT column

    Hi Chaps,
    I have a recordset that pulls data from a database, then presents the data in a table. The data is grouped by 'projid', repeated for every 'projid', with a show/hide control, to show all the 'jobid's' relating to that particular 'projid'
    This is what I have so far:
    Code:
    SELECT             
    tbl_projects.projid,
    tbl_projects.projtitle,
    tbl_projects.projdue, DATE_FORMAT(tbl_projects.projdue, '%%d/%%m/%%Y') as projdue_format,
    tbl_projects.projtype, 
    tbl_projects.projinvtype,
    tbl_projects.FK_custid,
    tbl_projects.projcompletedate
    tbl_languaget.langtname,
    tbl_doctype.doctypename,
    tbl_jobs.jobid,
    tbl_jobs.FK_projid,              
    tbl_jobs.jobname,              
    tbl_jobs.FK_langid,              
    tbl_jobs.jobpages,              
    tbl_jobs.jobshipped,
    tbl_jobs.jobinvsent,   
    tbl_jobs.jobtranslatorcharge,    
    'tbl_jobs' as fromtable,
    tbl_customers.custid,
    FROM tbl_projects  
    INNER JOIN tbl_jobs              
    ON tbl_projects.projid=tbl_jobs.FK_projid  
    INNER JOIN tbl_languaget              
    ON tbl_languaget.langtid=tbl_jobs.FK_langid  
    INNER JOIN tbl_customers              
    ON tbl_customers.custid=tbl_projects.FK_custid
    INNER JOIN tbl_costs
    ON tbl_costs.FK_custid=tbl_customers.custid 
    INNER JOIN tbl_doctype
    ON tbl_doctype.doctypeid=tbl_jobs.FK_doctypeid
    WHERE tbl_projects.projstatus='Complete'        
    AND tbl_projects.projinvtype='Costing Sheet'
    AND langtname!='TH'
    AND langtname!='ID'
    AND langtname!='KO'
    AND langtname!='JP'
    AND jobinvsent='y'
    AND FK_custid = %s
    ORDER BY projid ASC", GetSQLValueString($colname_rsInvPending, "int");
    $rsInvPending = mysql_query($query_rsInvPending, $conndb2) or die(mysql_error());
    //$row_rsInvPending = mysql_fetch_assoc($rsInvPending);
    $totalRows_rsInvPending = mysql_num_rows($rsInvPending);
    Code:
    // REPEAT - FOR EVERY PROJECT
      <?php
      $previousProject = '';
      if ($totalRows_rsInvPending > 0) {
      // Show if recordset not empty
        while ($row_rsInvPending = mysql_fetch_assoc($rsInvPending)) {
          if ($previousProject != $row_rsInvPending['projid']) {
          // for every Project, show the Project ID
      ?>
    Code:
    // SHOW/HIDE CONTROL
        <tr>
        <td colspan="9" class="highlight"><span class="blueBold"><a href="#" onclick="toggle2('proj1<?php echo $row_rsInvPending['projid'] ?>', this)"><img src="../../Images/plus.gif" border="0" /></a> <?php echo $row_rsInvPending['projid'] ?> - </a></span><span class="blueNOTBold"><em><?php echo $row_rsInvPending['projtitle'] ?></em></span></td>
        </tr>
    Code:
    // SHOW/HIDE
        <?php $previousProject = $row_rsInvPending['projid']; } ?>
        <tr class="proj1<?php echo $row_rsInvPending['projid'] ?>" style="display:none">
        <td>column 1</td>
        <td>column 2</td>
    What I want, is to put in another grouped by stage, where the 'projid's' themselves are in a show/hide region, grouped by 'projcompletedate' (year/month). 'projcompletedate' is in DATE format, but how to I get PHP/SQL to take the month and year and then group them correctly?

    Hi David, I'm not sure if I've got this right, would you mind looking at my latest code?:
    <table border="0" cellpadding="0" cellspacing="0" id="tblinvoice">
        <tr>
          <th>Job Title</th>
          <th>Type</th>
          <th>Language</th>
          <th>Translator</th>
          <th>Total</th>
          <th>Full</th>
          <th>Fuzzy</th>
          <th>Proof</th>
          <th>Full Price</th>
          <th>Discount Price</th>
          <th>Document Format</th>
          <th>Pages</th>
          <th>Typesetting Cost</th>
          <th>EN Proofreading Cost</th>
          <th>Total</th>
          <th>Translator Charge</th>
          <th>Profit</th>
          <th>Profit Percentage</th>
        </tr>
        <?php
          $previousMonth = '';
          if ($totalRows_rsInvPending > 0) {
          // Show if recordset not empty
          do ($row_rsInvPending = mysql_fetch_assoc($rsInvPending)) {
          if ($previousMonth != $row_rsInvPending['themonth']) {
          // for every Month, show the Month Name
       ?>
        <tr>
          <td colspan="18" class="highlight"><?php echo $row_rsInvPending['theyear'] ?> - <?php echo $row_rsInvPending['themonth'] ?></td>
        </tr>
        <?php $previousMonth = $row_rsInvPending['themonth']; } ?>
        <?php
          $previousProject = '';
          if ($totalRows_rsInvPending > 0) {
          // Show if recordset not empty
          while ($row_rsInvPending = mysql_fetch_assoc($rsInvPending)) {
          if ($previousProject != $row_rsInvPending['projid']) {
          // for every Project, show the Project ID
       ?>
       <tr>
        <td colspan="18" class="highlight"><span class="blueBold"><a href="#" onclick="toggle2('proj1<?php echo $row_rsInvPending['projid'] ?>', this)"><img src="../../Images/plus.gif" border="0" /></a> <?php echo $row_rsInvPending['projid'] ?> - </a></span><span class="blueNOTBold"><em><?php echo $row_rsInvPending['projtitle'] ?></em></span></td>
        </tr>
        <?php $previousProject = $row_rsInvPending['projid']; } ?>
        <tr class="proj1<?php echo $row_rsInvPending['projid'] ?>" style="display:none">
            <td><?php echo $row_rsInvPending['jobname']; ?></td>
            <td><?php echo $row_rsInvPending['projtype']; ?></td>
            <td><?php echo $row_rsInvPending['langtname']; ?></td>
            <td><?php echo $row_rsInvPending['translator']; ?></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
          </tr>
          <?php } while ($row_rsInvPending = mysql_fetch_assoc($rsInvPending)); ?>
          <?php } // Show if recordset not empty ?>

  • 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

  • Substracting number of days from date

    Hi all, I need to create a user exit to get a date value based on another variable. Basically, 100 days minus the first variable.
    var2 = var1 - 100
    How can I write this?
    Thanks.

    Ok, I figured it out. I had to declare variables of type d and then assign it.
    IF i_step = 2.
        data:zday type d,
              zday1 type d.
    *****Loops for Variable.*****************************************
        LOOP AT I_T_var_range
             INTO loc_var_range WHERE
                      VNAM = 'ZENDT' or
                      VNAM = 'ZENDATE'.
        zday = loc_var_range-low.
        zday1 = zday - 275.
    *      l_S_range-low = loc_var_range-low - 275.
          l_S_range-low = zday1.
          l_s_range-sign = 'I'.
          l_s_range-opt = 'EQ'.
          APPEND l_s_range TO E_T_range.
        ENDLOOP.
        EXIT.
      ENDIF.

Maybe you are looking for