NO of days in a month excluding weekdays

hi all
which is the easiest way to find out the no working days in a month excluding the weekdays in amonth
i used while loop to get the count of weekdays in a month
while condition
day(date)='sun'
i:=i+1;
loop
is there any other easiest way
thnks & regards

Not entirely sure i understand your question, but here's something that should be modifiable enough to fit your needs.
The 'datez' is just me generating dates for January and February 2008.
With the query i have asked for the number of days NOT Saturday or Sunday (so working days).
If you need to account for statutory holidays and the like you will need a static table as the last poster suggested.
ME_XE?with
  2     datez as
  3  (
  4     select
  5        to_date('01-jan-2008', 'dd-mon-yyyy') + (level - 1) as my_datez
  6     from dual connect by level <= to_date('01-mar-2008', 'dd-mon-yyyy') - to_date('01-jan-2008', 'dd-mon-yyyy')
  7  )
  8  select trunc(my_datez, 'MM'), COUNT(*)
  9  from datez
10  where to_char(my_datez, 'D') NOT IN (1,7)
11  group by trunc(my_datez, 'MM')
12  /
TRUNC(MY_DATEZ,'MM')                 COUNT(*)
01-JAN-2008 12 00:00                       23
01-FEB-2008 12 00:00                       21
2 rows selected.
Elapsed: 00:00:00.04Message was edited by:
Tubby

Similar Messages

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

  • Calculate number of working days in a month

    Hi All,
    I am trying to build a report to calculate the performance of a sales rep for the current month. This report has to exclude the holidays (saturday, sunday and one extra day in each month) in order get the exact performance. Could anyone suggest me on how to go about writing a Case statement which would get me the number of working days in a month excluding holidays.
    Thanks

    Hi,
    There are no direct oracle function that could be used to get the desired results.
    However you could try using something like
    SELECT COUNT( *)
    FROM
    (SELECT ROWNUM RNUM
    FROM ALL_OBJECTS
    WHERE ROWNUM <= TO_DATE('&1') - TO_DATE('&2') + 1
    WHERE TO_CHAR(TO_DATE('&2') + RNUM - 1, 'DY') NOT IN('SAT', 'SUN');
    Give the two date ranges that you want to look for with the highiest one first. i.e say for example - 01-FEB-2011 to 31-DEC-2010 would give the working days in JAN. However note that you might have to check for holidays related to that country/region (which could be added as a seperate table).
    If you need to get an extra day in addition to the weekends, please give the dates accordingly
    SQL> SELECT COUNT( *)
    2 FROM
    3 (SELECT ROWNUM RNUM
    4 FROM ALL_OBJECTS
    5 WHERE ROWNUM <= TO_DATE('01-FEB-2011') - TO_DATE('01-JAN-2011') + 1
    6 )
    7 WHERE TO_CHAR(TO_DATE('01-JAN-2011') + RNUM - 1, 'DY') NOT IN('SAT', 'SUN');
    COUNT(*)
    22

  • Getting days of month excluding Sundays

    i am using this query t calculate total days in a month but what i want is to select total days in month excluding sundays. I want total days in month which should not include Sundays. 
    Query:
    select day(EOMonth(GETUTCDATE())) as TotalDays

    Best thing for calculations like this is to have a calendar table in your database with required fields like date,day,year etc. then its just a matter of taking count from table by filtering on date range and checking for day values to exclude weekends etc
    Or you can create logic on the fly and use it like below
    DECLARE @Month int = 4,@Year int=2013
    DECLARE @StartDt datetime,@EndDt datetime
    SELECT @StartDt=DATEADD(mm,(@Year-1900)*12 +( @Month-1),0),
    @EndDt = DATEADD(mm,(@Year-1900)*12 +( @Month),0)-1
    SELECT SUM(CASE WHEN Day='Sunday' THEN 0 ELSE 1 END) AS DayCount
    FROM dbo.CalendarTable('2010-01-01','2010-02-28',0,0)
    CalendarTable can be found here
    http://visakhm.blogspot.in/2010/02/generating-calendar-table.html
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Schedule Executed weekly except for a specific day of the month

    Hi all,
    I need to create a schedule that run weekly every sunday at 9 PM, except for 2nd day of the month it will run at 7 AM.
    I have created 2 schedules:
    1. One to run weekly every sunday at 9 PM, but i don't know from where i can specify the days of the month the schedule will be inactive on it.
    * I have tried By Month Day option, and choose all days of the month except second day of the month to run on it.
    FREQ=WEEKLY; BYMONTHDAY=1,3,4,5,..,31; BYDAY= SUN; BYHOUR=21;
    But, on the schedule preview window as i have designed the schedule from oracle warehouse builder, shows sunday, 02, July for example.
    as an execution date for this schedule.
    which is not appropriate.
    2. Another job is created to run monthly on the 2nd day of the month,
    FREQ=MONTHLY; BYMONTHDAY=2; BYDAY= SUN; BYHOUR=7;
    So, please advice how to create schedules daily or weekly and neglect some days of month from it.

    Hi,
    You can use the exclude clause introduced in 10gR2 for this by creating a schedule when your job should not run and excluding it. An example is given below.
    Hope this helps,
    Ravi.
    create or replace procedure print_schedule_dates
       schedule in varchar2,
       start_date in timestamp with time zone default dbms_scheduler.stime(),
       number_of_dates in pls_integer default 10
    is
      date_after timestamp with time zone := start_date - interval '1' second;
      next_date timestamp with time zone;
    begin
      for i in 1 .. number_of_dates
      loop
        dbms_scheduler.evaluate_calendar_string
         (schedule, start_date, date_after, next_date);
        dbms_output.put_line(to_char(next_date,
                        'DY DD-MON-YYYY (DDD-IW) HH24:MI:SS TZH:TZM TZR'));
        date_after := next_date;
      end loop;
    end;
    begin
      dbms_scheduler.create_schedule('monthday2',
        repeat_interval=>'freq=monthly;bymonthday=2');
    end;
    exec print_schedule_dates('FREQ=WEEKLY;BYDAY=SUN;BYHOUR=21;exclude=monthday2',sysdate+1,30);
    exec print_schedule_dates('FREQ=WEEKLY;BYDAY=SUN;BYHOUR=21',sysdate+1,30);

  • Second working day of a month

    hello abaper,
      Cud u pls tel me how to get second working date of any month

    Function group                 Function group short text
    Function Module Name           Short text for function module
    CATSXT_UTIL
    CATSXT_GET_HOLIDAYS
    DTCO
    CHECK_HOLIDAY
    COLLECT_HOLIDAY_DT
    FB00
    BKK_CHECK_HOLIDAY
    HRFBN00GENERAL                 Function Group for FBN FMs
    HR_FBN_GET_HOLIDAY_PLAN_COST   Display FlexBen Holiday Cost in IT0377
    HRFBN00MISCEL                  Function Group for Misce. Plans FBN
    HR_FBN_UPDATE_HOLIDAY_QUOTA    Anmeldung eines Mitarbeiters für Sonstige Pläne
    HRPAYBE_SRD_UN05
    HR_BE_DAQ_UN05_NATUDAY_HOLIDAY Get nature of day
    HR_BE_UN05_PUBLIC_HOLIDAY      Get replacement day for public holiday falling on a day-
    off
    HRPAYDETM01
    HR_DE_CHECK_HOLIDAY
    HR_DE_GET_HOLIDAY
    HR_DE_REMOVE_HOLIDAY_FROM_LIST
    HRTIM00FORMS
    HR_FORMS_READ_HOLIDAYS
    RHBD
    RH_REQUEST_ON_BEFOREHOLIDAYS
    RH_REQUEST_ON_HOLIDAYS
    RPTM
    RP_GET_REMAINING_HOLIDAY
    SALP_UI                        User Interface for PerfDB
    SALP_UI_F4_HOLIDAY             f4-help for holiday & factory calendar
    SCA5                           Calendar: Additional functions
    HOLIDAY_CALENDAR_GET
    HOLIDAY_GET
    SCAL                           Calendar functions
    HOLIDAY_CHECK_AND_GET_INFO     Calendar function: Public holiday check with information
    SCTR                           Transport public holiday texts
    HOLIDAYTEXT_CORRECT_KEY
    HOLIDAYTEXT_FIND_OUT_RULES
    SFT1                           CHDO HOLIDAY => Gen. by RSSCD000
    HOLIDAY_WRITE_DOCUMENT         CHDO HOLIDAY => Gen. by RSSCD000
    SFT2                           CHDO HOLIDAYCAL => Gen. by RSSCD000
    HOLIDAYCAL_WRITE_DOCUMENT      CHDO HOLIDAYCAL => Gen. by RSSCD000
    WSAF
    WSAF_OUTBOUND_PUBHOLIDAYS
    try these...
    ALSO
    Date, Month and Popup Related Function Modules
    Date/Month Related Function Modules:
    DATE_COMPUTE_DAY u2013 Finds day of the month
    DATE_CONV_EXT_TO_INT  - user formatted date is converted to system date
    DATE_GET_WEEK  - convert date into year + week format
    DATE_TO_DAY u2013 gives weekday from date
    DATE_IN_FUTURE u2013 takes number of days and date  - gives future date in user format and system format
    MONTH_PLUS_DETERMINE u2013 add or subtract month from a date
    RH_GET_DATE_DAYNAME - return the day based on the date provied
    DATE_COMPUTE_DAY
    DATE_TO_DAY
    RP_CALC_DATE_IN_INTERVAL_SG u2013 add/subtract year/month/days from a date
    DAY_ATTRIBUTES_GET
    WEEK_GET_FIRST_DAY u2013 take input as YYYYWW and it gives first day of the week.
    MONTH_NAMES_GET u2013 language is only parameter. Returns internal table with months.
    MONTH_PLUS_DETERMINE u2013 subtract months from date

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

  • How do I find the start day of each month

    Hi all,
    Hope someone can give a a hand here I've to do a calender project for college and I'm not allowed to use any built in Java classes so fun all the way so far :-)
    I've got one question that is bugging me at the moment. and that is how to find the start day for each month in a year and store them in an array.
    I'm starting my week at Monday (0) and stopping at Sunday (6) and I do have a formula for discovering the first day in Jan of the given year its
    ((y-1900)*365 + (y-1901)/4)%7
    I was just wondering how I could amend this to find the first day in Feb, March etc.
    Any suggestions greatly accepted.
    Thanks in advance.

    Irish-Student wrote:
    newark maybe I didnt make clear exactly what I want to do.
    I have each day of the week starting at 0 for Monday up to 6 for Sunday I want to map what the start day of a month as a number between 0 and 6.
    The formula I have discovering the first day of Jan of a given year will give you 1 i.e. Tuesday
    what I need to do is find out what number between 0 and 6 the start day of each other month of a given year is.
    For example the 1st of Feb is a Friday which is 4 on the weekday map.
    Your suggestion of 31%7 won't work for this, sorry more than likely my fault for not being clearer in what my requirements were.
    Cheers for the help so far and yep your right not being able to use the built in classes is a pain :-)
    Edited by: Irish-Student on 03-Mar-2008 20:01This doesn't really change much of my first suggestion. If you can already calculate the first day of the month of January for any given year, then there's no problem figuring out the other months. Say I want to know the first day April 1, 1978. You already know how to find January 1, 1978. So find that. Then find the number of days between January 1 and April 1 (remember to account for leap years). Once you have the number of days, you can figure out how many weeks and days that is, and thus what day of the week it is.

  • Report for current day and current month

    Hi gurus,
    i 've a report, where i 've to display the values for qty and cost of the material for the current day and current month
    HOw can i do this in BEx Query designer..If any document plz share
    thanks
    rakesh

    hi Kolli
    here i want to filter the data on system date,
    i wnt the report to pick the date dynamically based on the system date.
    but i think restricting on calmonth and calday is not going to solve my scenario..
    rakesh

  • How can I set an event to repeat on a week day rather than a numerical day of each month?

    How can I set an event to repeat on a week day rather than a numerical day of each month? I see an option at the bottom of the repeat window .... but I cannot use it. Actually, when I try it freezes up my Calendar.
    Lorrene Baum Davis

    These scrrenshots are from Snow Leopard - I would think that Lion wouldn't be too much different.

  • Defining last day of previous month in ABAP

    All,
    I am a BW guy and hardly know ABAP. I have a requirement where I have to calculate last day of previous month and use it in the routines of the transformations.
    I have decided to define the Last day of previous month in Start routine and then use the global variable in Transformations to calculate further.
    The logic that i have used is outlined below.
             Define G_DATE in global declaration for further use in Transformations.
    In the Routine section,
            Assign G_DATE to SY-DATUM
            G_DATE + 6(2) = '01' (Replace last to field of date with '01' to establish first day of the current month)
            G_DATE = G_DATAE - 1 (To get to last day of previous month)
    My dilemma is to implement this in ABAP in Start routine of transformations. Please include the exact ABAP code that would be needed in Declarations and Routine section.
    Thanks in advance.

    Hi..,
    Go with the function module: LAST_DAY_OF_MONTHS
    So, Just determine the last month from the sy-datum and then use above function module and pick the last date of the month.
    Thanks,
    Naveen Inuganti.

  • Successive dates with  last day of that month being added to succesive date

    Hi ,
    I have a piece of code that displays the succuessive dates from the given date to tilll date with a date interval of 30 days. My requirement goes some thing like this. since the given date is '26-nov-08' the next successive date should be the number of days in nov(30) added to '26-nov-08'. that will be around 26-dec-08. For this date it has to add the number of days in December(31) to '26-dec-08' and that turns out to be '26-jan-09'. and this must go on till date.
    In the below code i have used 30 for the interval of 30 days but the interval has to the last day of the successive date's month( for dec the interval has to 31 and for january the interval has to be 31 and for february 28)
    select to_date('26-nov-08', 'dd-mon-yy') + (level - 1) * 30
    from dual
    connect by level <= trunc((sysdate-to_date('26-nov-08', 'dd-mon-yy'))/30 )Please advice

    hi ,
    the query sent by you is correct and could it be in corporated for this query :
    SELECT TRUNC(inst_due_date) + (LEVEL-1 ) * (ilpa_term_type),iloan_code,LOAN_AMT,FEE_AMT,
    LOAN_DATE,LOAN_STATUS_ID
    FROM (
    SELECT inst_due_date,sm.iloan_code,LOAN_AMT,
    FEE_AMT,
    LOAN_DATE,
    LOAN_STATUS_ID,
    decode(sm.ilp_term_type, 26 ,14,24,15,12,(select to_number(to_char(last_day(inst_due_date),'dd')) from dual)) as ilpa_term_type
    FROM ST_IL_SCHEDULE sc,ST_IL_MASTER sm
    WHERE sc.iloan_code = sm.iloan_code
    AND sc.inst_num = (SELECT MAX(inst_num) FROM ST_IL_SCHEDULE b WHERE b.iloan_code = sc.iloan_code)
    AND sc.iloan_code =123456789)
    CONNECT BY LEVEL <= TRUNC((TRUNC(SYSDATE)-TRUNC(inst_due_date))/(ilpa_term_type) )
    Here we are using the decode concept if ilp_term_type = 26 then 14 but we need to implement the code of adding the number of days to that month in place of this code :
    select to_number(to_char(last_day(inst_due_date),'dd')) from dual:
    Please advice

  • Display a metric differently only on last day of the month.

    Have a Daily transaction fact where unit cost of product is stored at a day/part num /business unit level.
    When we drag and drop date column and unit cost in the report like below we will have
    Date      cost
    Sep29     $10
    sep30     $12
    Oct1       $12
    Oct2       $14
    ..........ans so on
    The source sustem program runs on last day of the month around 8pm for setting up cost to reflect on 1st of every month
    But the nighly OBI load ( Runs at 2am every day) when incrementally updating Sep30 data picks up $12 from the erp and populates in OBI.
    But actually speaking, on Sep30 the cost was $10.
    There is no way of running the ERP program to run afer OBI load. Hence we need an expression in the RPD (not answers) saying
    when last day of the month (any month) the standard cost must be a previous day value.All other days the same value should be returned.
    Is this possible without impacting report performance ?
    So, when we drag and drop date and cost value the above report should change as
    Date        Cost
    sep29     $10
    sep30     $10
    Oct1       $12
    Oct2       $14
    Oct30     $12.5
    Oct31     $12.5
    Nov1      $13.5

    You can achieve the above requirement for current month alone with below steps:
    The solution requires to have a union report
    First part of the report will have Date and Cost fields with a report level date filter, Date NOT IN (TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_MONTH , 1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))))
    Second part of the report will have Date and Cost fields with a report level date filter Date IN (TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_MONTH , 1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))))In the second part of the report,
    Change the column formula for Date to display only Current_Date
    Change the column formula for Cost field with FILTER(Cost USING Date = Current_Date-1)
    Pls mark if correct/helpful.

  • How to calculate the number of days until your next birthday. Only using current month, day and birth month and day.

    I'm trying to calculate the number of days until your next birthday. Only using current month, day and birth month and day. I can get close but i'm way off. When i enter in the next day, the amount of days is supposed to be 364. This is where I am having problems. I know my code is way off. I just need some guidance please!
    Attachments:
    D5.7_1.vi ‏8 KB

    I just had a little fun with the Time Record...
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    D5.7_1_BD.png ‏19 KB

  • Current day and no of days in current month

    Hi all,
    can anbody tell me which object is used for current day and no of days in current month.

    Hi,
    USe /OSP/GET_DAYS_IN_MONTH Function Module, just give Date you will get No. Of days in that Month.
    Use SY-DATUM for current date.
    Ex:
    Data: dt type SY-DATUM.
    dt = SY-DATUM.
    so you get current date in dt.
    Thanks
    Reddy

Maybe you are looking for

  • Adding an "activity" via the contacts object failing

    Greetings. I unfortunately have not been able to attend the SDK class yet, but have been doing pretty good with it until this problem.  I found example code that shows how to do it and I createad a vb project with just that code in it.  The connectio

  • Problem with Live Data

    Hi Folks, I'm having a difficult time getting the Live Data function to work. I'm working on Mac OSX 10.3.9, running DW8. I've got the Apache server running (built into OS) and I've got MySQL and PHP successfully installed. I was able to create a dat

  • Move objects from DEV to QA

    My database is a 10.2.0.4 database running on HPUX IA64 box. I have a requirement to move a Package and a Trigger from DEV to QA. Package ETH_OWAI.CAI_E1_Trigger_pkg Trigger ETH_OWAI.CAI_F4311_AIUDR Could someone please help me with the steps as to h

  • ACS SE: no clean shutdown / sometimes looses IP config

    Hello, we recently upgraded a ACS applicance from: Cisco Secure ACS: 3.2.3.11 Appliance Management Software: 3.2.3.11 Appliance Base Image: 3.2.2.2 Status: Appliance is functioning properly to: Cisco Secure ACS: 3.3.1.16 Appliance Management Software

  • Hide system tray notification after login via RD web access

    Hi, I have a question. Is there a way to set that the notification in system tray won't appear after login into RD web access? And related question. I recently rename server and in this notification still shows old one. "Your computer is connect to: