Calculate the number of days in a month

I need to do a calculation in my query based upon the number of days in the month. The report is broken down by cal year / month.
Is there an easy way of identifying these values in the query?
Regards.

Hi,
  This can be done by writing an user exit code to determine the number of days in the month.
Sample Code :
<
CHECK i_step = 2.
  READ TABLE i_t_var_range WITH KEY vnam = 'XXXX'
                           INTO loc_var_range.
  IF sy-subrc EQ 0.
    beg_date(6) = loc_var_range-low(6).
    end_date(6) = loc_var_range-low(6).
    beg_date+6(2) = '01'.
    end_date+6(2) = '01'.
    ADD 1 TO end_date+4(2).
    IF end_date+4(2) = '13'.
      end_date+4(2) = '01'.
      ADD 1 TO end_date(4).
    ENDIF.
    no_days = end_date - beg_date.
    l_s_range-sign = 'I'.
    l_s_range-opt  = 'EQ'.
    l_s_range-low  = no_days.
    APPEND l_s_range TO e_t_range.
  ENDIF.
>
Hope this helps..
Thanks & Regards,
Pradeep

Similar Messages

  • 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

  • I wanted to know how do you calculate the number of days between two dates

    i wanted to know how do you calculate the number of days between two dates in java ? i get both the dates from the database. i guess there are many issues like leap year and Febuary having diff no of months ..etc.

    thanks..
    I solve my problem as
    public class MyExample {
        public static void main(String a[]) {
            String stdate = "2009-03-01";
            java.sql.Date currentDate = new java.sql.Date(System.currentTimeMillis());
            java.sql.Date preDate = java.sql.Date.valueOf(stdate);
            System.out.println(currentDate);
            System.out.println(preDate);
    //        int dateCom = preDate.compareTo(currentDate);
    //        System.out.println(dateCom);
            long diff = currentDate.getTime() - preDate.getTime();
            int days = (int) Math.floor(diff / (24 * 60 * 60 * 1000));
             System.out.println(days);
    }

  • How to calculate the number of days worked for a given period

    I need to calculate the number of days worked by contractor employees for a time period to be entered by a user. I am building a query on an infoset which contains employee information including contract start date and contract end date for the employee.
    Ideally I'd like the user to enter the time period which should be reported on e.g. 01.08.2009 to 31.08.2009
    The report should then identify all the contractor employees which were working during this period and to work out how many days they worked during this period. Obviously the contract start and end dates could fall both inside and outside the reporting period.
    Can this be done and if so, do you have any suggestions as to how to do it?
    Thanks.

    hi
    So here you will first have to load the master data table employee in one internal table and read this table with the variables entries.
    Your code in the reporting exit should look like that.
    bye
    data : wa_employee type /bi0/pemployee.
    When 'ZDATE1'
    if i_step = 2.
    LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'ZDATE2'.
    clear l_s_range.
    clear wa_employee
    1- select the entries from table employees
    select single employee dateto datefrom
    from /bi0/pemployee
    into corresponding fields of wa_employee
    where dateto le loc_var_range-low
    and datefrom ge loc_var_range-high.
    if sy-subrc eq 0.
    CALL FUNCTION 'FIMA_DAYS_BETWEEN_TWO_DATES'
       EXPORTING
           i_datum_von  = wa_employee-datefrom
           i_kz_ult_von = 'X'
           i_datum_bis  = wa_employee-dateto
           i_kz_ult_bis = 'X'
           i_szbmeth    = '1'
       IMPORTING
          e_tage       = no_days.
           l_s_range-low  = no_days.
           l_s_range-sign = 'I'.
           l_s_range-opt  = 'EQ'.
          APPEND l_s_range TO e_t_range.
              ENDIF.
            ENDIF.
    endloop.
    ENDIF.
    Boujema

  • Create a field routine to calculate the number of days per month

    Hi Experts,
    I need to create a field routine to count the number of days per month based on 0CALMONTH. Could you give me some inputs on how to do it?
    Thanks!

    Hi,
    Create InfoObejct and then insert it in InfoSource/InfoCube/DSO then write simp,e code for that based on your  0CALMONTH values.
    You just copy and pas this in SE38 and see the result and implement for your requirements.
    REPORT  ztest1.
    Data: zsydt type sy-datum,
          zd(2) type n,
          zm(2) type n,
          zy(4) type n,
          zcmnth TYPE /bi0/oicalmonth,
          znds TYPE /osp/dt_day.
          zsydt = sy-datum.
          zd = '01'.
          zm = zsydt+4(2).
          zy = zsydt+0(4).
          CONCATENATE zy zm zd INTO zsydt.
          CALL FUNCTION '/OSP/GET_DAYS_IN_MONTH'
                EXPORTING
                  iv_date = zsydt
                IMPORTING
                  ev_days = znds.    "No.of days in month.
          write:/ zd.
          write:/ zm.
          write:/ zy.
          write:/ zsydt.
          write:/ znds.
    Thanks
    Reddy

  • FM to get the number of days in Year,month and days by giving number of day

    Hi ALL,
    This is quit differnt.
    I need to give input the 'start date' and the 'number of days' and get the total days from the start date in year,month and day format.
    for example.
    start date :01.01.2009
    number of days as 32
    then i should get
    years:0
    months :1
    days :1
    Pleas help me out.

    hi Anusha,
    first u pass the date and the days to the following fm you will get the result date....
    data:date type sy-datum,
          r_date(10) type c.
    date = sy-datum.
    CALL FUNCTION 'CALCULATE_DATE'
    EXPORTING
       DAYS              = '32'
       MONTHS            = '0'
       START_DATE        = date
    IMPORTING
       RESULT_DATE       = r_date
    write:/ r_date.
    then you need to pass the result date and the date to the following fm to get the required output...
    CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
        EXPORTING
          date1                   = r_date
          date2                   = date
        IMPORTING
          years                   = v_years
         months                 = v_months
        days                     = v_days
        EXCEPTIONS
          invalid_dates_specified = 1
          OTHERS                  = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    here u will get the difference in days,  months and year...
    i hope u wil get help from this...
    regards
    Ashu  Singh

  • How to get the number of days of a month belonging to a date interval

    Hi, i am getting mad around a problem, i have 2 dates and a month, i wanto to retrieve the number of days belonging to the month that are in the interval.
    eg:
    month january 2011 . begin_date = 11/JAN/2011, END_DATE 30/MAY/2011 result is 21
    month january 2011 . begin_date = 11/DEC/2010, END_DATE 10/JAN/2011 result 10
    month january 2011 .begin_date = 02/FEB/2011 , END_DATE 25/may/2011 result 0
    month january 2011. begin_date = 03/JAN/2011 , END DATE 05/JAN/2011 result 3
    and so on ...
    i appreciate any suggestion
    thank you
    Andrea

    Oh, I didnt see your result.
    SQL> with t as
      2  (select  to_date('11/01/11','dd/mm/yy') from_dt,
      3           to_date('30/05/11','dd/mm/yy') to_dt,
      4           'Jan-11' mnth from dual
      5           union all
      6           select  to_date('11/12/10','dd/mm/yy') from_dt,
      7           to_date('10/01/11','dd/mm/yy') to_dt,
      8           'Jan-11' mnth from dual
      9           union all
    10           select  to_date('02/02/11','dd/mm/yy') from_dt,
    11           to_date('25/05/11','dd/mm/yy') to_dt,
    12           'Jan-11' mnth from dual
    13           union all
    14           select  to_date('03/01/11','dd/mm/yy') from_dt,
    15           to_date('05/01/11','dd/mm/yy') to_dt,
    16           'Jan-11' mnth from dual
    17           )
    18  select from_dt,to_dt,mnth,
    19         greatest(
    20              least(last_day(to_date(mnth,'Mon-yy')),to_dt)
    21              -
    22              greatest(to_date(mnth,'Mon-yy'),from_dt)+1
    23                 ,0) cnt
    24  from t;
    FROM_DT   TO_DT     MNTH          CNT
    11-JAN-11 30-MAY-11 Jan-11         21
    11-DEC-10 10-JAN-11 Jan-11         10
    02-FEB-11 25-MAY-11 Jan-11          0
    03-JAN-11 05-JAN-11 Jan-11          3

  • How to get the number of days in a month?

    hi all
    is there any way to get the number of days in a given month with a given year? for instance, if year is 2004 and the month is July or February, how can i get the number of days? thanks.

    Gee, I don't know ... Maybe this:
    Calendar cal = Calendar.newInstance();
    cal.set(Calendar.YEAR, 2004);
    cal.set(Calendar.MONTH, Calendar.FEBUARY);
    System.out.println("max days in month: " + cal.getActualMaximum(Calendar.DAY_OF_MONTH));
    Do you not bother reading what people have already posted? Read the API docs on the Calendar class.

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

  • SSAS Tabular - return number of days in given month using month's start date?

    Is there a way to return the number of days in a month by providing just the month date or month start date?
    We have a time table, but it is at monthly (not daily) granularity.
    So I can't just count rows between start/end of month.
    I need to be able to divide by the number of days in a given month and can't seem to find a way to get number of days in that given month.
    Thanks!

    Hi,
    According to your description, you want to get the number of days in a month with the month's start date, right?
    In this case, we can get the first day of next month using DateAdd function, and then use DateDiff function to calculate the number of days in this month. Here is a sample query for your reference.
    WITH
    MEMBER Measures.Today AS vba!Now()
    member measures.FirstDayOfNextMonth as dateadd("m",1,Measures.Today)
    member measures.daysnumber as datediff("d",Measures.Today,measures.FirstDayOfNextMonth)
    select Measures.daysnumber on 0
    from
    [Adventure Works]
    Reference
    http://msdn.microsoft.com/en-us/library/hh510163.aspx
    http://office.microsoft.com/client/helppreview14.aspx?AssetId=HV080007558&lcid=1033&NS=EXCEL%2EDEV&Version=14&tl=2&pid=CH080007543
    http://office.microsoft.com/client/helppreview14.aspx?AssetId=HV080007559&lcid=1033&NS=EXCEL%2EDEV&Version=14&tl=2&pid=CH080007543
    Regards,
    Charlie Liao
    TechNet Community Support

  • Determine the number of days in a False period in a Temporal Boolean

    Hi all,
    I need to determiine the number of days based on a condition that lies on the gaps between the periods.
    My input consists of multiple periods. The length of the gap is the condition to determine the start date for summation. However, there can be multimple gaps between my instances that satisfy this condition and I need the last one that satisfies it.
    For example:
    period 1: 1-1-1990 until 31-12-1992
    period 2: 1-1-1994 until 31-12-1996
    period 3: 1-1-1998 until 31-12-1999
    period 4: 1-6-2000 until 31-12-2009
    The condition for the start date is the last gap greater than 1 year. In this example, the start date should be the start date of period 3: 1-1-1998, because this is the period after the last gap >= 1 year. Period 2 also has a previous gap of >= 1 year, but this period should NOT be selected.
    My first idea was to use a TBR function: to determine relevant periods (based on the gaps before and after), calculate the amount of days per relevant period and add those up. However, if I want to do that I need to calculate the number of days in the gaps and I don't see how to do that, since I cannot determine a day difference across periods (end date period 1 until start date period 2).
    Any help/ other solution ideas?
    Kind regards, Els

    This was an interesting puzzle which you can solve from a couple of different angles.
    Firstly, you can use inferred relationships to infer a relationship "the following periods" (ie. the periods that follow the current one). My rules looked like this:
    the period (the other period) is a member of the following periods if
       the other period start date > the period start date
    the period’s next start date = InstanceMinimum(the following periods, the period start date)From here it should be easy to see if there was a gap of more than a year, and find the most recent period after a year-long gap. Of course you need to deal with the situation of the last period, when there is no 'next' period, presumably you would use the date of assessment in that case, but I'll leave that as an exercise for the reader.
    A completely different way of doing it is to use the TemporalConsecutiveDays function to find a date where a gap of 365 days exists, then select periods in which there is a gap immediately before the start of that period. Here are some rules that :
    there is a period that applies if
       ExistsScope(the periods)
          TemporalOnOrAfter(the period start date) and
          TemporalOnOrBefore(the period end date)
    there is a year-long gap if
       TemporalConsecutiveDays(365, 365, there is not a period that applies)
    the period starts after a year-long gap if
       ValueAt(the period start date, there is a year-long gap)
    the start date for calculation = InstanceMaximumIf(the periods, the period start date, the period starts after a year-long gap)Hopefully one of these is suitable for your needs.
    cheers,
    Steve.

  • Number of days in a month - 0CALDAY

    Hi,
    I have a query where I am calculating the average daily sales for each month. For this I need to know the number of days in each month. How can I do this? For instance, it should give 31 for Jan, 28/29 for Feb, 31 for Mar and so on. I am using OCALMONTH as the input variable.
    Thanks for your help.
    Uday

    Hi Uday,
    I have a few modifications in the code
    Data: xdate type d,
          ip_year(4) type N,
          ip_month(2) type N.
    Types : Begin of ty_month_days,
           month(2) type N,
           days(2) type N,
           End of ty_month_days.
    Data : it_month_days type ty_month_days occurs 0 with header line.
    ip_year = 2006.
    ip_month = 01.
    do 12 times.
        CONCATENATE ip_year ip_month '01' INTO xdate.
        xdate = xdate + 33.       "this date is in the next month
        xdate+6(2) = '01'.        "first day of next month
        xdate = xdate - 1.        "last day of xmonth
        it_month_days-month = xdate+4(2).       "number of days of xmonth.
        it_month_days-days = xdate+6(2).
        append it_month_days.
        ip_month = ip_month + 1.
    enddo.
    This code stores Month and No. of days in the internal table it_month_days.
    You can access this internal table for your calculations
    This should help.
    Regards,
    Praveen.
    Message was edited by: praveen mathew

  • Calculated item divided by number of days in a month

    Hello.
    I'm trying to create a calculated item, that is supposed to represent a column member, divided by the number of days in a month that's selected from the dashboard prompt.
    I know that I need an SQL function to get the number of days, but I don't think that you can use SQL functions when creating calculated items.
    Is there a way to do this?

    Looks like you are thinking too much
    Use expression builder in the rpd and then just use available functions without 2nd thought.
    if helps mark

  • Find number of days in current month

    Hi Folks ,
    I needed some help in knowing the number of days in any month ... I need to develop an application which will be triggering a mail with an excel attachment at the end of every month ...after populating the excel sheet from an Oracle database ..
    Kindly help...
    Thx..

    Thx a lot for your immediate reply .. I tried using
    the calender class. But for my application .. i need
    to automate this process by sending a mail every last
    day of the month... but i am finding it a bit
    difficult to really automate setting the current
    month to the Timer class
    Timer timer;
         public Reminder ( int seconds ) { 
              timer = new Timer ( ) ;
    timer.schedule( new RemindTask ( ), seconds*1000
    000 ) ;
         }The Calendar class is still the best solution IMHO.

  • How to calcuate the number of days

    Hi Friends,
    can some one help me out .. how to dispaly the number of days depending upon the from and to date selected by the user.
    eg :-
    there is one self service form.. in which three fields are there, they are 1) From date
    2) To date
    3) No of days
    now my requirement is, user selects from date and to date and i need to calculate the number of days he is selected and display in No of days field. can some one help me out logic for this.
    how to retrive from date and to date dynamically to my function.
    apart from writing function .. can we use $FLEX$ becoz two dates are valuesets.
    seeking for a solution,
    thanks in advance

    This doesn't sound like something that will be easy to do.
    A few questions:
    1) What flexfield are you referring to?
    2) What Self Service page?
    3) Can the 'No of days' ALWAYS be calculated? Or do you just want to default it so the user can modify it?

Maybe you are looking for

  • Need to Prevent Adobe Application Manager for upgrading to Creative Cloud

    I have successfully packaged Dreamweaver CS5&CS5.5 via Adobe Application Manager Enterprise Edition v2.1 and after a successfully deployed via SCCM Dreamweaver runs perfect. Unfortunatly upon the first launch of the icon on the desktop of "Adobe Appl

  • Pci-e tuner card not recognized on z68ma-ed55

    I just built a new system using the z68 motherboard and everything seems to be working except my hauppauge hvr1800 tv tuner. I was hoping maybe some of you experts might have some insight. I have already updated the bios, per msi's advice but that di

  • Can't add any more photos to iPhoto 09

    This is a strange one. I've been using iPhoto for years, have 19,164 photos contained within a 134GB iphoto database. Yesterday I was adding about 350 new photos to iphoto, all Nikon RAW format from a D700. Everything was imported fine, I created an

  • "Select default PDF handler" greyed out in Acrobat XI and Reader X

    MIS just installed Acrobat XI for me, and now all PDFs from the web open in the Browser, which is not the way I usually operate.  I went to Preferences > General in both programs, and in both the "Select default PDF handler" option is greyed out.  An

  • CREATE TEMPORARY TABLE USING EXECUTE IMMEDIATE

    Hi All, i have a question, how can i create a temporary table using EXECUTE IMMEDIATE ?? Like: CREATE GLOBAL TEMPORARY table new_table as (Select * from old_table); Thanks, Edited by: xDeviates on Jun 11, 2012 3:13 PM