How to calculate the number of months between two string as yyyymm

Dear all,
I have two month string like yyyymm e.g. 201003 -- 201105. Now I want to calculate the number of months bertween these two month string? How can I do that? Thanks.

888099 wrote:
Hi,
Hope this will help :
     public static void main(String[] args) {
          Calendar cal1 = new GregorianCalendar(2010, 02, 01);
          Calendar cal2 = new GregorianCalendar(2011, 04, 01);
          int years = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR);
          int months = cal1.get(Calendar.MONTH) - cal2.get(Calendar.MONTH);
          System.out.println("number of months : "+Math.abs(years*12 + months));
     }Or with only Strings :
     public static void main(String[] args) {
          String s1 = "201002";
          String s2 = "201104";
          int years = Integer.valueOf(s1.substring(0,4)) - Integer.valueOf(s2.substring(0,4));
          int months = Integer.valueOf(s1.substring(4)) - Integer.valueOf(s2.substring(4));
          System.out.println("number of month : "+Math.abs(years*12 + months));
     }Edited by: 888099 on 28 sept. 2011 05:49Full code solutions will not help the OP, he will be back here with a different Date question. Posters here try to nudge the OP to figure out the solution himself.

Similar Messages

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

    HI all
    can any body give the FM name which calculates the number of months between any two dates that are inputted
    thanks in advance

    Try this in ur source code of FM.....include the import and Export...as given
    ""Local interface:
    *"  IMPORTING
    *"     REFERENCE(BEGDA) LIKE  PA0001-BEGDA
    *"     REFERENCE(ENDDA) LIKE  PA0001-ENDDA
    *"  EXPORTING
    *"     REFERENCE(DIFF_MONTHS) TYPE  I
    *"  EXCEPTIONS
    *"      ENDDA_GRTR
      DATA : SMONTH TYPE I,
             EMONTH TYPE I,
             SDATE TYPE I,
             EDATE TYPE I,
             SYEAR TYPE I,
             EYEAR TYPE I,
             MONTHSTOBEADDED TYPE I,
             YRDIFF TYPE I,
             DIFF TYPE I.
    Calculating the months to be added
      SMONTH = BEGDA+4(2).
      EMONTH = ENDDA+4(2).
    Finding the difference in years
      SYEAR = BEGDA+0(4).
      EYEAR  = ENDDA+0(4).
      IF SYEAR <> EYEAR .
        SYEAR = SYEAR + 1.
        DIFF =  ( 12 - SMONTH ) + 1.
        YRDIFF  = EYEAR - SYEAR.
        IF YRDIFF > 0 .
          DIFF = DIFF + ( YRDIFF * 12 ).
        ENDIF.
        DIFF = DIFF + EMONTH.
      ELSE.
        DIFF = ( EMONTH - SMONTH ) + 1.
      ENDIF.
    DIFF_MONTHS = DIFF.
    ENDFUNCTION.

  • How to calculate the no. of weekdays between two active dates

    Hi all,
    I need to calculate the no. of weekdays between two days.
    For Example:
    If i want to know the number of weekdays between 17-NOV-2008 to 7-DEC-2008 its 10 excluding sat and sun.
    how to do that if the period is more?
    like 1-JAN-2006 to 12-APR-2007
    Thanks in advance..
    Regards,
    Manoj

    NEXT_DAY(start_date - 1,'SUNDAY') is first sunday >= start_date. NEXT_DAY(end_date - 7,'SUNDAY') is last Sunday <= end_date. Therefore:
    (NEXT_DAY(end_date - 7,'SUNDAY') - NEXT_DAY(start_date - 1,'SUNDAY')) / 7 + 1 is number of Sunday's between start_date and end_date. Same way:
    (NEXT_DAY(end_date - 7,'SATURDAY') - NEXT_DAY(start_date - 1,'SATURDAY')) / 7 + 1 As a result, number of weekdays between start_date and end_date is:
    business_day_count := end_date - start_date + 1 -((NEXT_DAY(end_date - 7,'SUNDAY') - NEXT_DAY(start_date - 1,'SUNDAY')) / 7 + 1 + (NEXT_DAY(end_date - 7,'SATURDAY') - NEXT_DAY(start_date - 1,'SATURDAY')) / 7 + 1) or
    business_day_count := end_date - start_date - 1 -(NEXT_DAY(end_date - 7,'SUNDAY') - NEXT_DAY(start_date - 1,'SUNDAY')) / 7 - (NEXT_DAY(end_date - 7,'SATURDAY') - NEXT_DAY(start_date - 1,'SATURDAY')) / 7 or:
    SELECT end_date - start_date - 1 -(NEXT_DAY(end_date - 7,'SUNDAY') - NEXT_DAY(start_date - 1,'SUNDAY')) / 7 - (NEXT_DAY(end_date - 7,'SATURDAY') - NEXT_DAY(start_date - 1,'SATURDAY')) / 7 FROM DUAL; The above code assumes business day count between two dates includes both start and end dates. Keep in mind, the above code is NLS dependent.
    SY.

  • How to calculate the number of sent/received emails of a certain domain

    Thank you for what you have helped me with!
    How to calculate the number of sent/received emails of a certain domain in a certain period? It is Messaging Server 5.2, Directory Server 4.2. Is there a log option for this?
    Thank you.

    Not sure where you find, "LOG_MESSSAGE_ADD". I don't actually find this option in the documentation.
    The domains that mails are coming from and being sent to are certainly logged in the normal mail.log, so why mess with additional logging options? If you're talking about "LOG_CONNECTION", I actually see no additional data that is useful to you.
    If you decide to change the option.dat, you do indeed need to
    imsimta cnbuild (note, it's not cnrebuild)
    imsimta restart
    If I were facing the same issue, I'd be looking at the log parsing perl script, and simply modifying it to do what I wanted.

  • How to calculate the number of operations in Undo/Redo stack?

    How to calculate the number of operations in Undo/Redo stack?
    I tried to override UndoManager.pushUndo method and increment "operationsCounter" there, but pushUndo is called each time I make a change in text.
    Another idea was to override EditManager.finalizeDo and use "operationsCounter" there, but finalizeDo is private...
    Do you have any idea?

    Hi Richard,
    Thanks for the reply. I suggested that existed the more simple way to implement this

  • Count the number of records between two key values (BTREE)

    How can I count the number of keys between two values?
    I'm using python driver, and BTREE access method.
    ====>
    ideally what I want is to average a whole time-series data set (the intervals can change) to a given number of points. The keys are the time stamps and the values are the data that needs to be averaged. I need to count the number of records between two time stamps so that I can divide that number by the number of points i need, and average the data. What is the best way to do this?  Or should I just keep the intervals for the time stamp constant and use RECNO access method?
    Thank you
    (first post btw.. and why aren't there many people in stackoverflow who answer Berkeley DB questions?)

    BDB is an embedded db and it does not have any internal counters or statistics that you could grap to use for this.    You will need to do it manually.
    You can create a cursor, grap the records you want, each time you get the next record you bump a counter.
    If you are using RECNO, you can use a cursor to get the record number of the record (DB_GET_RECNO), and if all you data is in
    sequentail records with no missing records you can figure out the total count by take last rec # - initial rec # + 1 to get a total count.
    If you switch over to the SQL API, you can issue a SQL query to give you a count.  Select count(*) Where .......
    Since you have to grab the data anyway, then best may be to count records as you go along.
    thanks
    mike

  • How can i get number of days between two dates represented by two dates?

    how can i get number of days between two dates represented by two date objects. One is java.sql.Date, the other is java.util.Date?

    tej_222 wrote:
    But how do I do that conversion. from java.sql.date and java.util.date to calender?
    -thanks for the quick response.You may find the following utility code samples useful:
    [http://balusc.blogspot.com/2007/09/calendarutil.html]
    [http://balusc.blogspot.com/2007/09/dateutil.html]
    ganeshmb wrote:
    (date1.getTime() - date2.getTime())/(1000*60*60*24) should do.
    getTime returns millsecond value of date object and the difference divided by no of milliseconds in a day should fetch you the difference in terms of days.This doesn't respect the DST. Use java.util.Calendar.

  • How to identify the follow up relationship between two service ticket

    Hi Folks,
    How to identify the follow up relationship between two service ticket ?
    Please help me on this...
    Regards,
    Shashi K, Reddy

    Hi Pepe !
    Thank you for the answer, but I dont find this structure ET_DOC_FLOW.....
    Please let me know is that structure is correct ......
    Regards,
    Shashi K, Reddy
    shashikumarreddy at gmail dot com

  • How to Calculate number of months between two dates

    Hi All,
       In one of the fomr developments, I have to calculate the
    Number of Days
    Number of Months ( Considering Leap Year) provided by the dates, end user enters in the form,
    After going thorugh some forum discussion, I have come to know about so many things which were not clear till now.
    I have gone through various forums too,  some one suggets to make use of FORM CALC and some other JAVA SCRIPT. But the logic i want to build in java script.
    The most interesting point is the DATE object is not getting created when i write  the below code
      var startDate = new DATE(oYear, oMonth, oDay);
    I am still not clear, that really the date object gets created in Adobe form If so the why the alert box is getting populated when i write below lines
    var oTemp = startDate.getFullYear();
    xfa.host.messagebox(oTemp);
    So, there are so many unclear things,
    If any one can help me by suggesting the approach and how to build the logic in the JavaScript I would be really thankful
    Regards
    PavanChand

    Hi,
    ChakravarthyDBA wrote:
    Hi
    I want number of Sundays between two dates
    example
    number of Sundays count between '01-04-2013' and '30-04-2013' in one select query I have to include this as sub query in my select statement.Here's one way:
    SELECT       early_date
    ,       late_date
    ,       ( TRUNC (late_date + 1, 'IW')
           - TRUNC (early_date,        'IW')
           ) / 7       AS sundays
    FROM       table_x
    ;This does not depend on your NLS settings.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
    Point out where the statment above is getting the wrong results, and explain, using specific examples, how you get the right results from the given data in those places.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • 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

  • How to calculate the number of user connections in a report?

    Hi,
    I would like to have a report which automatically calculate the number of connections per user.
    Thanks for your answer.
    Regards

    Hi,
    What do you mean by number of connections? Do you mean how many times each user has run a specific report?
    Thanks

  • 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

  • How to calculate the number of vowels from a txt file. Pls give me a hand!!

    Guys! How do i calculate the number of vowels from a txt file? I have to create a program to count the number of words, sentence, and vowels. So far I had managed to count the number of words. Now I need help on counting sentence and vowels! Pls give me a hand guys!

    I first have to read from the file not the string.I
    know how to read from a file. Now the problem ishow
    to compare a character from a txt file!You fail to understand, that you have read the data
    from the file into a string. Now loop over all
    characters in the string. Forget about the file.
    KajOr forget the scanners just as others have told you. Just read the file character by character using a FileReader.
    Kaj

  • How to get the number of days between 2 given dates

    Hi all,
    How can I find the number of days between any 2 given dates.
    Thanks

    Hi
    Here's a dirty way:
    If you've got two Date objects in Java, call getTime() on each one (which gives you a value in milliseconds), then subtract the two millisecond values, and divide the result by the number of milliseconds in a day (24 * 60 * 60 * 1000). There's more `elegant' ways to do this, but this method only requires one line of Java.
    Best wishes
    Kevin

Maybe you are looking for

  • Passing Value to Java Script Code in a BSP

    Hi Guys, In order to use BSP Extension in my BS i need to specify the "ID" for the field / Text area / Table i want to work with. Now these elements (Field / Text Area / Table) are created by SAP CRM automatically and i am not sure how i can get the

  • My iPad is disabled, ITunes did not work, i erased, still disabled.

    My iPad is disabled, with many attempts of trying to connect it to itunes it did not work. I decided to log in icloud and erase the iPad since i had no important things in it, but that also didn't work. It's still disabled. HELP PLEASE!

  • DVCPro HD 720 25p

    Hi, I'm just sitting down to edit a short film and noticed that all the clips have come in at 50fps despite the DOP telling me they were shot at 25fps. They seem to play fine in an FCP project with a sequence set to 25fps, so what's the deal? Is ever

  • How can I use single source images in text?

    I'm using RoboHelp HTML 11, and I want to use single source images of icons in text, so that I have the ability to update the source image, as needed, and all instances of the image are updated automatically. The look is as follows: I've tried snippe

  • How do I control the selection highlighting colors assigned to Layers?

    When new layers are created in the Layers panel, they are set to a default selection highlighting color. The color for each new layer changes, sequencing through a list of color options. For my personal use, whether or not it's the lighting in my off