Number of a day of an year without saturday and sunday

Hi,
How can I get the number of the day of an year?
How can I remove, from this number the saturday and the sunday? Should I check day by day?
Thanks, bye bye.

Or you can function NEXT_DAY, some math and table dual:
to_char(to_date(6,'j'),'Day') is NLS independent way of representing Sunday and to_char(to_date(5,'j'),'Day') is NLS independent way of representing Saturday.
NEXT_DAY(start_date - 1,to_char(to_date(6,'j'),'Day')) is first sunday >= start_date. NEXT_DAY(end_date - 7,to_char(to_date(6,'j'),'Day')) is last Sunday <= end_date. Therefore:
(NEXT_DAY(end_date - 7,to_char(to_date(6,'j'),'Day')) - NEXT_DAY(start_date - 1,to_char(to_date(6,'j'),'Day'))) / 7 + 1 is number of Sunday's between start_date and end_date. Same way:
(NEXT_DAY(end_date - 7,to_char(to_date(5,'j'),'Day')) -
NEXT_DAY(start_date - 1,to_char(to_date(5,'j'),'Day'))) / 7 + 1 As a result, number of weekdays between start_date and end_date is:
end_date - start_date + 1 -((NEXT_DAY(end_date - 7,to_char(to_date(6,'j'),'Day')) -
NEXT_DAY(start_date - 1,to_char(to_date(6,'j'),'Day'))) / 7 + 1 +
(NEXT_DAY(end_date - 7,to_char(to_date(5,'j'),'Day')) -
NEXT_DAY(start_date - 1,to_char(to_date(5,'j'),'Day'))) / 7 + 1) or
end_date - start_date - 1 -(NEXT_DAY(end_date - 7,to_char(to_date(6,'j'),'Day')) -
NEXT_DAY(start_date - 1,to_char(to_date(6,'j'),'Day'))) / 7 -
(NEXT_DAY(end_date - 7,to_char(to_date(5,'j'),'Day')) -
NEXT_DAY(start_date - 1,to_char(to_date(5,'j'),'Day'))) / 7 or:
SELECT end_date - start_date - 1 -(NEXT_DAY(end_date - 7,to_char(to_date(6,'j'),'Day')) - NEXT_DAY(start_date - 1,to_char(to_date(6,'j'),'Day'))) /
       7 - (NEXT_DAY(end_date - 7,to_char(to_date(5,'j'),'Day')) - NEXT_DAY(start_date - 1,to_char(to_date(5,'j'),'Day'))) / 7
FROM DUAL; Now:
WITH t AS (
           SELECT  to_char(to_date(6,'j'),'Day') sunday,
                   to_char(to_date(5,'j'),'Day') saturday,
                   DATE '2009-01-01'             start_date,
                   DATE '2009-12-31'             end_date
             FROM  dual
SELECT  end_date - start_date - 1 -(NEXT_DAY(end_date - 7,sunday) - NEXT_DAY(DATE '2009-01-01' - 1,sunday)) /
        7 - (NEXT_DAY(end_date - 7,saturday) - NEXT_DAY(start_date - 1,saturday)) / 7
  FROM  t
END_DATE-DATE'2009-01-01'-1-(NEXT_DAY(END_DATE-7,SUNDAY)-NEXT_DAY(DATE'2009-01-0
                                                                             261
SQL> SY.

Similar Messages

  • Calculate the number of days in a year excluding Saturday and Sunday

    Hi All,
    I need to get the number of days in a year excluding Saturday and Sunday for HR module and then subtract the public holidays.
    Can some let me know how this needs to be done while loading data from one infocube to another.
    Is there any Function module for the same so that i can write any start routines.
    And also is there any table available for Tcode-SCAL with which i can write any start routines.
    Kindly help me as soon as possible.
    Regards,
    Kumar

    Hi Harish
    Refer to the screenshot for Import and Export parameters
    Code
    FUNCTION ZBI_FM_GET_HOLIDAYS .
    *"*"Local Interface:
    *"  IMPORTING
    *"    VALUE(DATE_FROM) TYPE  SCAL-DATE DEFAULT SY-DATUM
    *"    VALUE(DATE_TO) TYPE  SCAL-DATE DEFAULT SY-DATUM
    *"    VALUE(FACT_CAL) TYPE  SCAL-FCALID DEFAULT SPACE
    *"    VALUE(ONLYFACT_DAYS) TYPE  CHAR1 OPTIONAL
    *"  EXPORTING
    *"    REFERENCE(HOLIDAYS) TYPE  I
    *"  TABLES
    *"      DAY_ATTRIBUTES STRUCTURE  CASDAYATTR
    *"  EXCEPTIONS
    *"      FACTORY_CALENDAR_NOT_FOUND
    *"      HOLIDAY_CALENDAR_NOT_FOUND
    *"      DATE_HAS_INVALID_FORMAT
    *"      DATE_INCONSISTENCY
    DATA: LT_DAY_ATTRIBUTES TYPE TABLE OF  CASDAYATTR WITH HEADER LINE.
    DATA: LV_LINES TYPE SY-SUBRC.
    DATA: DATE1 LIKE DATE_FROM,
    DATE2 LIKE DATE_TO.
    *if from date is gt to date then interchange the dates and multiply the result with -1.
    IF DATE_FROM GT DATE_TO.
    DATE2 = DATE_FROM.
    DATE1 = DATE_TO.
    ELSE.
    DATE1 = DATE_FROM.
    DATE2 = DATE_TO.
    ENDIF.
    CALL FUNCTION 'DAY_ATTRIBUTES_GET'
    EXPORTING
    FACTORY_CALENDAR                = FACT_CAL
    *  HOLIDAY_CALENDAR                = ' '
    DATE_FROM                        = DATE1
    DATE_TO                          = DATE2
    LANGUAGE                        = SY-LANGU
    * IMPORTING
    *  YEAR_OF_VALID_FROM              =
    *  YEAR_OF_VALID_TO                =
    *  RETURNCODE                      =
    TABLES
    DAY_ATTRIBUTES                  = LT_DAY_ATTRIBUTES
    EXCEPTIONS
    FACTORY_CALENDAR_NOT_FOUND      = 1
    HOLIDAY_CALENDAR_NOT_FOUND      = 2
    DATE_HAS_INVALID_FORMAT          = 3
    DATE_INCONSISTENCY              = 4
    OTHERS                          = 5 .
    IF SY-SUBRC = 0.
    IF ONLYFACT_DAYS = 'X'.
    DELETE LT_DAY_ATTRIBUTES WHERE FREEDAY EQ SPACE.
    ELSE.
    DELETE LT_DAY_ATTRIBUTES WHERE WEEKDAY LT 6.
    ENDIF.
    DESCRIBE TABLE LT_DAY_ATTRIBUTES LINES LV_LINES.
    HOLIDAYS =  LV_LINES.
    *    IF DATE_FROM GT DATE_TO.
    *      HOLIDAYS = HOLIDAYS * -1.
    *    ENDIF.
    ELSEIF SY-SUBRC = 1.
    RAISE FACTORY_CALENDAR_NOT_FOUND.
    ELSEIF SY-SUBRC = 2.
    RAISE HOLIDAY_CALENDAR_NOT_FOUND.
    ELSEIF SY-SUBRC = 3.
    RAISE DATE_HAS_INVALID_FORMAT.
    ELSEIF SY-SUBRC = 4.
    RAISE DATE_INCONSISTENCY.
    ENDIF.
    ENDFUNCTION.

  • Day between two dates excluding Saturday and Sunday

    Hi,
    I have the Requirement like : there are two inputs in query 1)startdate and 2)end date when end user enter the start date and end date the sql query has to retrive the number of days between given start and end dates, and it should be retrivied with two condition 1)all sundays between the above dates excluded 2)second and fourth Saturday of the month in between the start and end dates has to be excluded .
    example start date:01-may-09
    end date: 16-may-09
    expected output:13

    Balaji.M wrote:
    Hope this will be helpful for you.
    SELECT dates,
    TO_CHAR(dates, 'D'),
    TO_CHAR(dates, 'DAY'),
    TO_CHAR(inner.dates, 'W')
    FROM (SELECT TO_DATE('01-may-09') + LEVEL - 1 dates
    FROM DUAL
    CONNECT BY LEVEL <= (TO_DATE('16-may-09') - TO_DATE('01-may-09')) + 1) inner
    WHERE ( ( TO_CHAR(inner.dates, 'D') = 7
    AND TO_CHAR(inner.dates, 'W') NOT IN(2, 4)
    OR TO_CHAR(inner.dates, 'D') not in (1,7)
    You can replace the start date (two place) and end date (one place) by variables and check.Of course we have to be aware of local NLS settings:
    SQL> SELECT dates,
      2  TO_CHAR(dates, 'D'),
      3  TO_CHAR(dates, 'DAY'),
      4  TO_CHAR(inner.dates, 'W')
      5  FROM (SELECT TO_DATE('01-may-09') + LEVEL - 1 dates
      6  FROM DUAL
      7  CONNECT BY LEVEL <= (TO_DATE('16-may-09') - TO_DATE('01-may-09')) + 1) inner
      8  WHERE ( ( TO_CHAR(inner.dates, 'D') = 7
      9  AND TO_CHAR(inner.dates, 'W') NOT IN(2, 4)
    10  )
    11  OR TO_CHAR(inner.dates, 'D') not in (1,7)
    12  );
    DATES     T TO_CHAR(D T
    01-MAY-09 5 FRIDAY    1
    02-MAY-09 6 SATURDAY  1
    03-MAY-09 7 SUNDAY    1
    05-MAY-09 2 TUESDAY   1
    06-MAY-09 3 WEDNESDAY 1
    07-MAY-09 4 THURSDAY  1
    08-MAY-09 5 FRIDAY    2
    09-MAY-09 6 SATURDAY  2
    12-MAY-09 2 TUESDAY   2
    13-MAY-09 3 WEDNESDAY 2
    14-MAY-09 4 THURSDAY  2
    15-MAY-09 5 FRIDAY    3
    16-MAY-09 6 SATURDAY  3
    13 rows selected.
    SQL>Day 1 on my local database is Monday, not Sunday.

  • Number of the day in the year

    Hi,
    I have a requirement to add the number of the day in the year to the message and concatenate with HHMM as shown below
    like this :1205001...12:HH,05:MM; 001(1st day of the year)
    ex2: 0204365...02:HH;04:MM;DDD:365(last day of the year)
    ex3: 0209236..02:HH;09:MM;DDD:236:(236th day of the year)...
    How can i achieve this? any standard functionality?
    please advise.
    Regads

    Hi ,
                 Is it the current system date you wanna concatenate?  Anyways this can be achieved by message mapping using standard functions
    input--------------------------------------------------------------------\
                                                                                concat()--------> target field
    currentdate()--->Transformdate(yyyy/MM/dd,hh:mm:DDD)----------------------/
    If its not system date then you can input any field like "2012/01/02"  or change the format of input date transformdate (the first field).
    Regards
    Anupam

  • Query to get holidays including saturday and sunday by giving month and year as input

    query to get holidays including saturday and sunday by giving month and year as input.

    Hi,
    Create a table for holidays.  You could INSERT one row for each holiday in each year, but it might be more useful if you just create 1 row for every day, with a column that tells whether that day is a holday, part of a weekend, or a work day.
    See
    http://forums.oracle.com/forums/message.jspa?messageID=3351081
    for a user-defined function that tests if a given DATE is holiday.
    You could use such a function when populating the table I mentioned earlier.

  • Plan order is considering saturday and sunday as working day.

    Hi All,
    I have a problem where saturday and sunday is being conidered as working day when a plan order is created (Either manually or Automatically). But in calender assigned to this plant, saturday and sunday is assigned as holiday.
    But when we convert the same plan order which has Saturday as Order start, the Basic start date of production order is moved to Firday.
    EG. Plan order - XXXXXX has order finish date as 22-Aug-2011. Inhouse lead time is 2 days. So system takes 20-Aug-2011 as order srat date in plan order.
    But when same Plan order is converted to Production order, then the Basic order start date is moved to 18-Aug-2011 and it says that 20-Aug-2011 and 21-Aug-2011 is maked as holiday in calender.
    Can some one please suggest why is plan order considering Saturday and Sunday as working day.

    Hi,
    Check the factory calendor assigned to plant which is referenced in plan order and teh factory calendor assigned to work center which is used in elad time scheduling in production order.. are they same? 
    Check how they ahve maintined..?

  • Mail Escalation only on working days i.e except saturday and sunday

    Hi Experts,
    I have a scenario that mail should be escalated to 5 levels.
    First Level condition----
    > complaint date + 2days.
    Second level condition if 1st is not satisfied Compalint date + 4 days.
    next is complaint date + 6 days.
    Problem is when saturday or sunday comes then complaint should not be escalted iam doing this also by getting out of program but iam unable to trigger that complaint which was caught on sat and sunday....
    Small Hint shall be highly appreciated and rewarded..
    Regards,
    Bohra

    Hi,
    You can do this by changing the Day Types Selection Rules.
    Time Management->Work Schedules->Day Types->Define Selection Rules
    Rule - <same as existing>
    D.Ty.Wkdy - <same as existing>
    D.typ.Sat - 1111
    D.typ.Sun - 2222
    Thanks.
    Edited by: Ilyas Shaik Md on Jan 16, 2012 10:13 PM
    Edited by: Ilyas Shaik Md on Jan 16, 2012 10:13 PM

  • How to get the data for last 3rd business day and also include saturday and sunday if its a wednesday?

    Hi All,
    I have a simple query which is below:-
    Declare @reportdate date
    set @reportdate= (DATEADD(dd,-5,getdate()))
    select * from dbo.Table
    where date IN (@reportdate)
    I need this query to pull the data for the last 3rd business day .So lets say today is monday then i need the data for last week wednesday which is 3 business days back from monday, if today is a tuesday it would be for last thursday ( as 3 business days for
    tuesday would be thursday). But if today is wednesday then i need to be last 3rd business day which is last friday and i also need to get the data for saturday and sunday.
    Can someone please help me how cani change my filter to do this?
    Please let me know if i am still unclear.
    Thanks

    Hi SqlDev12,
    Based on my understanding on your requirement, you can reference the below sample.
    CREATE TABLE BusinessTable
    Bdate DATE,
    Wd VARCHAR(10)
    ;WITH Cte(DT,WD) AS
    SELECT CAST('20150401' AS DATE),DATENAME(WEEKDAY,CAST('20150401' AS DATE))
    UNION ALL
    SELECT DATEADD(DAY,1,DT),DATENAME(WEEKDAY,DATEADD(DAY,1,DT)) FROM Cte
    WHERE DT<GETDATE()
    INSERT INTO BusinessTable SELECT * FROM Cte
    SELECT * FROM BusinessTable
    SET DATEFIRST 7 -- Set Sunday as the first day of a week
    DECLARE @givenDay DATE ='20150415' --Wednesday
    SELECT * FROM BusinessTable
    WHERE Bdate BETWEEN
    --For Monday and Sunday, select last wednesday
    (CASE WHEN DATEPART(WEEKDAY,@givenDay) IN(1,2) THEN DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay)-1,0))
    --For Tuesday and Wednesday, last week's Thursday and Friday
    WHEN DATEPART(WEEKDAY,@givenDay) IN(3,4) THEN DATEADD(DAY,-5,@givenDay)
    --For Thursday and Friday, current week's Monday and Tuesday
    WHEN DATEPART(WEEKDAY,@givenDay) IN(5,6) THEN DATEADD(DAY,-3,@givenDay)
    --For Saturday, current week's Wednesday
    ELSE DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay),0)) END)
    AND
    (CASE WHEN DATEPART(WEEKDAY,@givenDay) IN(1,2) THEN DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay)-1,0))
    WHEN DATEPART(WEEKDAY,@givenDay) IN(3) THEN DATEADD(DAY,-5,@givenDay)
    WHEN DATEPART(WEEKDAY,@givenDay) IN(4) THEN DATEADD(DAY,-3,@givenDay)
    WHEN DATEPART(WEEKDAY,@givenDay) IN(5,6) THEN DATEADD(DAY,-3,@givenDay)
    ELSE DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay),0)) END)
    DROP TABLE BusinessTable
    If you have any feedback on our support, you can click
    here.
    Eric Zhang
    TechNet Community Support

  • How to count days between two dates excluding saterady and sunday

    Hi all
    iam working on oracle sql/plsql.
    In my application , i need to caliculate leave days between two dates excluding saterady and sunday
    Please tell me the solution if any one knows
    thanks in advance ,
    balu

    More modern version:
    WITH date_tab AS
    (SELECT TO_DATE ('&from_date', 'dd-MON-yyyy')
    + LEVEL
    - 1 business_date
    FROM DUAL
    CONNECT BY LEVEL <=
    TO_DATE ('&to_date', 'dd-MON-yyyy')
    - TO_DATE ('&from_date', 'dd-MON-yyyy')
    + 1)
    SELECT business_date
    FROM date_tab
    WHERE TO_CHAR (business_date, 'DY') NOT IN ('SAT', 'SUN');Thank you,
    Tony Miller
    Webster, TX
    Never Surrender Dreams!
    JMS
    If this question is answered, please mark the thread as closed and assign points where earned..

  • Original GI date should display closest day when Saturday and Sunday comes

    Hi Guys,
    I am getting Original GI Date as After deducting Transit time from Original Delivery Date.
    But i want to fullfill  the below requiremnt also.
    the Original GI Date should be then the working day defined in the calendar of the shipping point. Thus if the calculation gives  Original GI Date to be Sunday 4.3.2012 then it should changed to the closest previous working date which is Friday 2.3.2012 (calendar 'YT').
    Any one help me how to execute the above requiremnt.
    regards
    reddy.

    Hi,
    Pass your GI date to below given FM, it will return you the day of the week.
    CALL FUNCTION 'DATE_COMPUTE_DAY'
    EXPORTING
    DATE = GI_DATE
    IMPORTING
    DAY = day_of_week_num
    EXCEPTIONS
    OTHERS = 8.
    the value returned by this FM in day_of_week_num will be between 1 to 7, 1 representing Monday and 6 = Saturday and 7 = sunday.
    Now if your working days are from monday to friday then simply check the value returned by this FM is it is 6 then you can subtract 1 for last friday or add 2 for next monday and in the same fashion if value returned is 7 then subtract 2 for last friday and add 1 for next monday in GI date.
    For adding and subtracting value from GI date you can use FM RP_CALC_DATE_IN_INTERVAL.  And if you need to check some settings related to Factory calander then you can use FM DATE_CONVERT_TO_FACTORYDATE.
    Regards,
    Durgesh.

  • Serial number is invalid (after 2,5 years of use and legal purchase of package)

    Hi,
    Since 20 days my CS6 says that my serial number is invalid. I purchased my software 2,5 ago, CD and serial included. I tried to set it up again, but it switches to the trial version (8 days to go..... ) and won't accept the serial number.
    What can I do?

    Hi Juliette verberk,
    Kindly try the below mentioned links.
    Invalid serial number error
    Error "The serial number is not valid for this product" | Creative Suite
    Thanks,
    Atul Saini

  • How can i get a number of working days in a month PL/SQL

    How can i get a number of working days in a month(excluding Saturday and Sunday) in a query in PL/SQL ?

    Please do a search before posting
    sql>
    select count(*)
    from(
    select trunc(sysdate,'month')+rownum-1 dy
    from all_objects
    where rownum <= last_day(sysdate) - trunc(sysdate,'month')+1)
    where to_char(dy,'fmday') not in ('sunday','saturday');
    COUNT(*) 
    23
    Message was edited by:
            jeneesh
    Please try yourself to change the query to one that doesn't use a subquery..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to calculate number of working days

    Hi experts,
    I need to determine the number of working days from two given dates. Below is my example.
    1. Posting Date
    2. Clearing Date
    3. Processing Time in Days
    The formula is:
    Processing Time in Days = Posting Date - Clearing Date
    However, the above result should exclude non-working days such as Public Holidays, Saturdays and Sundays.
    This is to be done in my Transfer Rule.
    Can someone help me with this.
    Points will be assigned as usual.
    Thanks!

    Hi,
    With referece to  Florin Wach Reply in the following link:
    Re: FM to get number of working days in a date range for a calender
    Use the update rule(routine) for <i>Processing Time in Days</i> as below:
      DATA: date_begin         TYPE sy-datum,
             date_end           TYPE sy-datum,
             current_date       TYPE sy-datum,
             working_indicator  TYPE SCAL-INDICATOR,
             workdays           TYPE I,
             factory_calendar   TYPE SCAL-FCALID.
       date_begin       = DATA_PACKAGE-PSTNG_DATE.
       date_end         = DATA_PACKAGE-CLEAR_DATE.
       factory_calendar = '01'.
       current_date = date_begin.
       DO.
          IF current_date > date_end.
             EXIT.
          ENDIF.
         CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
              EXPORTING  DATE                 = current_date
                         FACTORY_CALENDAR_ID  = factory_calendar
              IMPORTING
                         WORKINGDAY_INDICATOR = working_indicator
              EXCEPTIONS
                   CALENDAR_BUFFER_NOT_LOADABLE = 1
                   CORRECT_OPTION_INVALID       = 2
                   DATE_AFTER_RANGE             = 3
                   DATE_BEFORE_RANGE            = 4
                   DATE_INVALID                 = 5
                   FACTORY_CALENDAR_NOT_FOUND   = 6
                   OTHERS                       = 7.
         IF SY-SUBRC <> 0.
            workdays = 0.
            MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
            EXIT.
         ENDIF.
         IF working_indicator IS INITIAL.
            ADD 1 TO workdays.
         ENDIF.
         ADD 1 TO current_date.
      ENDDO.   
    Result  = workdays.
    With rgds,
    Anil Kumar Sharma .P

  • Count days between two dates without weekend

    Hi,
    I need a solution in query or another thread, that returns the count of days between two dates without consider weekend (saturday and sunday) , I have the columns of type Date, and the return need in format of hours in one column hh:mm:ss and days in another column.
    Regards
    Jonas

    Hi and welcome to the forum.
    Keep in mind that you can do a search on this forum.
    Your question has been asked before.
    Some other pointers:
    http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551242712657900129
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:185012348071

  • Calculating number of days without weekend and holidays

    Hallo all,
    can someone help me with a formular to calculate the number of days with Crystal Reports 2008 between two dates without weekends and holidays
    eg.
    date one = 03/24/2010
    date two = 03/29/2010
    Result should be 4 days as 03/27 and 03/28 will be a weekend.
    Plus how to exclude holidays ?
    Thank you very much
    Gerald

    As Doug mentioned, Holidays are very location specific, and are you talking about "corporate holidays" where the company is closed, or "public holidays" where banks (<g>) are closed?
    I'd suggest setting up a calendar table (if you don't have one already), one record per date.  You could make it work-days only, days-off only, or all dates with a flag to indicate if it is a work date.  You could then use that to count the number of work days.  By using a table, you wouldn't have to change any code to (a) extend your calendar to the following year, or (b) change holiday dates if the holidays change.  (I'm thinking corporate holidays, where the company might be closed Friday 12/24/10 in observation of Christmas, but would usually only close on the 25th.)
    HTH,
    Carl

Maybe you are looking for