How do i get number of days between 2 dates?

How do i get number of days between 2 dates?
and the result must be in int.
for example
Ex. startdate: 2006-06-01 enddate: 2006-06-30 and the result is: 30
how to do so? thx

mel
Iv'e used this method. It assumes startdate,enddate and days have been defined before but you could pass them as args.
void days()
    try
      Date d1 = DateFormat.getDateInstance().parse(startdate);
      Date d2 = DateFormat.getDateInstance().parse(enddate);
      long days = (d2.getTime()-d1.getTime())/1000/60/60/24;
      days = ""+days;
    catch (ParseException e)
      System.out.println("Invalid date format");
  }It actually gets the duration in ms and divides down to days.
Regards
Chris

Similar Messages

  • How  can I get number of days between 2 dates ?

    How can I get number of days between 2 dates ?
    Give me answer as soon as possible.....

    Mukesh_Prajapat wrote:
    How can I get number of days between 2 dates ?
    Give me answer as soon as possible.....Is google broken again?
    [How To Ask Questions The Smart Way|http://www.catb.org/~esr/faqs/smart-questions.html]

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

  • Getting number of days between 2 dates

    Hello All,
    I require the number of days between 2 dates.
    The number of days is between low date : PR Date (not an input variable) and the high date.
    I have created an customer exit variable to get sy-datum in made it as formula variable.
    I have also created a formula variable for PR Date , and subtracted the 2 dates.
    It is not giving the correct result.
    Any suggestions.
    Thanks & Regards,
    VL

    Read through this web link.  It will show you how to calculate the days between 2 dates directly in your BEX query.
    No exit needed to calculate this.
    http://teklink.co.uk/sap/sap-bi-bw-how-to-use-replacement-path-variables-to-perform-date-calculations-in-the-bex-analyzer/

  • Confused - How to Calculate Number of Days Between Dates but Exclude Weekend Dates If There Hasn't Been a Weekend Update

    Hello -
    I've been tearing my hair out over this problem i'm trying to solve, probably just been staring at it too long which is making it worse -
    I have a series of open support tickets which are supposed to be updated on a daily basis, the problem is that they aren't always being updated daily.  So, the business wants to know the number of days from when a ticket was last updated and today's
    date.  I have this basic calculation and it's working fine, however now the business wants to exclude weekends from the calculation.  The other problem is that some reps DO go in on weekends and update their tickets, so sometimes there will be updates
    made on weekend dates.
    To give an example -
    Today's date is 2014-02-10 (Monday).  A ticket was last updated last Thursday, 2014-01-30.  The difference between the two dates is 11, so it's been 11 days since the ticket was last updated.  Now, if I exclude Saturdays and Sundays, then
    it's actually been 7 days since the ticket was last updated.  I'm not sure how to do this in T-SQL.
    Now, to further complicate the problem, sometimes a ticket IS updated on a Saturday or Sunday.  So, if a ticket was updated on 2014-02-02 (Sunday), then it should be counted.  Again i'm not sure how to do this. 
    What gets me is that this is probably fairly simple and i've just been staring at it too long.  In the meantime, can someone offer some guidance?
    Thanks!!

    I've adapted this from a function on my blog. you will need to add set the YourTicketTable to where ever your tickets are stored.
    CREATE
    FUNCTION [dbo].[CalcWorkDaysBetween](@StartDate
    As DateTime,@EndDate
    AS DateTime)
    RETURNS
    INT AS
    BEGIN
    SET @EndDate
    =DATEADD(DAY,1,@EndDate)
    DECLARE @Count
    AS Int= 0
    DECLARE @Date
    As Date=@StartDate
    WHILE @Date
    < @EndDate
    BEGIN
    IF (DATEPART(WEEKDAY,@Date)IN(1,7)
    OR (SELECT
    Count(*)
    FROM YourTicketTable WHERE TicketDate=@Date)=1)
    BEGIN
    SELECT @Count = @Count
    + 1
    END
    SELECT @Date=DATEADD(Day,
    1,@Date)
    END
    RETURN
    DATEDIFF(DAY,@StartDate,@EndDate)- @Count
    END
    Regards,

  • How to get difference in days between 2 dates excluding weekends

    Hi all,
    i have a requirement, to calculate the difference between 2 dates, in days.
    eg: 01/08/2007 and 05/08/2007.
         Difference = 4 days.
    But here my actual requirement is i have to calculate this difference excluding weekends (saturday n sundays).
    eg: 01/08/2007 -
    Thursday
         05/08/2007 -
    Monday
    so now Difference = 2 days.
    Please help me regarding this.
    Points will be rewarded for helpfull answers.
    Thanks in Advance.
    Regards,
    Vineel

    see these codes of rich
    report zrich_0003.
    data: begin of itab occurs 0,
          datum type sy-datum,
          end of itab.
    data: weekday like dtresr-weekday.
    data: number_lines type i.
    parameters: p_sdatum type sy-datum,
                p_edatum type sy-datum.
    itab-datum = p_sdatum.
    append itab.
    do.
      if itab-datum = p_edatum.
        exit.
      endif.
      itab-datum = itab-datum + 1.
      call function 'DATE_TO_DAY'
           exporting
                date    = itab-datum
           importing
                weekday = weekday.
      if weekday = 'Sat.'
        or weekday = 'Sunday'.
        continue.
      endif.
      append itab.
    enddo.
    describe table itab lines number_lines.
    write:/ 'Number of days between dates is', number_lines.
    and
    report zrich_0001.
    parameters: p_start type sy-datum,
                p_end   type sy-datum.
    data: idays type table of   rke_dat with header line.
    data: workingdays type i.
    call function 'RKE_SELECT_FACTDAYS_FOR_PERIOD'
         exporting
              i_datab               = p_start
              i_datbi               = p_end
              i_factid              = 'P8'  " Fact Calender ID
         tables
              eth_dats              = idays
         exceptions
              date_conversion_error = 1
              others                = 2.
    describe table idays lines workingdays.
    write:/ workingdays.
    I want to find the No.of working days between the two dates
    regards,
    srinivas

  • 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

  • How to calculate number of days between two date in Template design?

    Hello guys
    I have a situation where I have to create a template that returns data, and one of the thing of the existing report is that there is a column that is actually the number of days between start date and end date columns..
    So in template, how would I be able to do the same? I have start date and end date columns on the template, now when I created another column using expression like end date - start date and preview the template, I am getting errors saying :
    Caused by: oracle.xdo.parser.v2.XPathException: Cannot convert 03/31/2009 to number.
         at oracle.xdo.parser.v2.XSLStylesheet.flushErrors(XSLStylesheet.java:1534)
         at oracle.xdo.parser.v2.XSLStylesheet.execute(XSLStylesheet.java:521)
         at oracle.xdo.parser.v2.XSLStylesheet.execute(XSLStylesheet.java:489)
         at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:271)
         at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:155)
         at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:192)
    Please advice
    Thanks

    Hi
    There is an extension function you can use, from the javadoc:
    date_diff
    public static long date_diff(java.lang.String format,
    java.lang.String fromDate,
    java.lang.String toDate,
    java.lang.String locStr,
    java.lang.String tzID)
    Method to get the difference between two dates in the given locale. The dates need to be in "yyyy-MM-dd" format. This function supports only Gregorian calendar.
    Parameters:
    format - the format to which the difference is required; allowed formats are y (for Year), m(for month), w(for week), d(for day), h(for hour), mi(for minute), s(for seconds) and ms(for milliseconds)
    fromDate - the first date
    toDate - the second date
    locStr - locale string -> lang-Territory
    tzID - timezone ID ->http://java.sun.com/j2se/1.4.2/docs/api/java/util/TimeZone.html
    Returns:
    the difference in dates in the desired format
    For example
    <?xdoxslt:date_diff(‘d’,’2009-09-14’, ‘2009-09-20’,’en-US’,1)?>
    give a result of 6
    You can substitute in columns for the dates, just remember the date format required.
    Regards
    Tim

  • 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 number of days between Calendar objects

    Hi,
    I need to calculate the number of days between two Calendar objects. Here is some sample code:
    Calendar now = Calendar.getInstance();
    now.set(Calendar.HOUR_OF_DAY, 0);
    now.set(Calendar.MINUTE, 0);
    now.set(Calendar.SECOND, 0);
    now.set(Calendar.MILLISECOND, 0);
    // get a calendar that represents a day in the past
    Calendar aDayInThePast = getADayInThePast();
    aDayInThePast.set(Calendar.HOUR_OF_DAY, 0);
    aDayInThePast.set(Calendar.MINUTE, 0);
    aDayInThePast.set(Calendar.SECOND, 0);
    aDayInThePast.set(Calendar.MILLISECOND, 0);
    // how can I calculate the number of days ago this was??
    //it would also be useful to get back a negative number if the day is in the future

    My favorite answer so far is reply 15 by Marc__: http://forum.java.sun.com/thread.jspa?threadID=488668&start=15

  • How to calculate number of days between fixed date and hire date in schema

    i want to calculate the number of days between a fixed date en the hire date (infotype 041)
    If i read the documentation  right, i should use the following command:
    HRS=YDXA02
    Variable 3 (the x) is the fixed data.
    My question is how do i program the variable x?
    Let's say the date 01.01.2008
    Any help would be welcome

    I assume we are talking about PCR for payroll. In this case look at documentation for operation NUM:
    OOOOOO
    Xnnnnn
    X     Table
    nnnnn Table field
    nn    Date type 'nn' from the Date Specifications infotype (0041)
         Date types are taken from table T548Y.
    Your operation would look like:
      NUM=Faaesb
          F          Fixed indicator for deadline calculation
           aa           Date type: Start date of period to be
                        calculated; if the date type is not 'nn,'
                        the second position is left blank.
             e          Unit, in which the duration is calculated:
                        T = days
                        W = week
    s         End date of period to be calculated:
              (blank)  End of current payroll period
              J        End of current calendar year
              A        Start of current calendar year
              B        Start of WPBP period
             No other specifications are possible.
    So it depends on what kind of fixed date you need.
    Hope it helps,
    Carlos.

  • How can I calculate the maximum number of days between two dates in a range of dates?

    I have a column of dates spanning the couse of a few months.  I would like to know if I can calculate the maximum number of days between each row and display the highest number.  I currently have another column that calculates the days betwen the rows and I am currently just looking at the totals and highlighting the highest period.
    Is this possible?  Any help or suggestions are appreciated.
    Thank you,
    Trevor

    This sounds totally possible,  Can you post a screen shot of your table to make responding more focused?  If you mean you want to:
    A) compute the difference (in days) between two date in the same row, then
    B) find the max duration (in days)
    Here is my take on this problem:
    D2 = C2-B2
    select D2 and fill down
    F1=MAX(D)
    to perform the conditional formatting (to highlight the max duration) select column D, then set up conditional formatting as shown in the 1st image

  • Calculate number of days between two festival dates in payroll schema

    Hi Experts,
    According to my company policy:
    If an empl termination happens before Eid festival of the current year, then the pro-rated Eid bonus (yearly) is based on:
    (The duration between Eid Festival date of previous year - Eid festival date of current year.)/350 days
    Time Evaluation is not implemented in the system. Only payroll is implemented.
    My question: How can I capture the number of days between (Eid Festival date of previous year - Eid festival date of current year) in the payroll schema ?
    Regards,
    Somdeb.

    Hi,
    You can try using date specification. If you update last year eed holiday date for the employee then you can use the operand F along with NUM to get days between last eed holiday and current payroll period last day.
    i.e NUM=FaaT 0
    F is operand to query date specification.
    aa is the date specification.
    T is for unit and it gives number of days
    next space is for current payroll period last day and 0 will reset alternate date to zero if no date specification is mentioned.
    Basically this will give number of days from date mentioned in date type aa to current period last day. For more info you can go through documentation on operand F for NUM.
    Let us know if this helps.
    Regards,
    Poorvi.

  • Find Exact number of days between two dates

    How can get the exact number of days between two dates?

    An example of business days calculation in SQL */
    /* The algorythm is: */
    /* 1) Take the absolute difference between the dates */
    /* to_date('&todate') - to_date('&frdate') */
    /* 2) Subtract the weekends (number of weeks in the range */
    /* TRUNC(to_date('&todate'),'D') = 1st day of week that */
    /* end of period is in */
    /* TRUNC(to_date('&frdate'),'D') = Last day of week that */
    /* start of period is in */
    /* So subtracting these two gives the number of days */
    /* between the two dates but including all of the days in */
    /* the weeks that the dates start and end in. When this */
    /* number is divided by 7 it gives the number of weeks. */
    /* Multiplying by 2 gives the number of weekend days.     */
    /* 3) Subtract 1 day if the ending date is on a saturday */
    /* DECODE(to_char(to_date('&todate'),'D'),7,-1,0) */
    /* --> If the day of the week is saturday (7), returns -1 */
    /* 4) Subtract 1 day if the start date is on a sunday */
    /* DECODE(to_char(to_date('&frdate'),'D'),1,-1) */
    /* --> If the day of the week is sunday (1), returns 1 */
    /* 5) Add one day to make the range inclusive (The '1 + ' ) */
    /* Author: Kenneth Atkins ([email protected]) */
    /* http://www.olywa.net/katkins/oratip */
    define frdate = '&1'
    define todate = '&2'
    set verify off
    select      
         '&frdate' From_Date
         ,'&todate' To_Date,
         1 + to_date('&todate') - to_date('&frdate') -
         ((TRUNC(to_date('&todate'),'D') - TRUNC(to_date('&frdate'),'D'))/7)*2
         + DECODE(to_char(to_date('&todate'),'D'),7,-1,0)
    + DECODE(to_char(to_date('&frdate'),'D'),1,-1,0) Business_Days
    from dual
    Here is an example of running the script:
    SQL> @busdays 01-AUG-96 15-AUG-96
    FROM_DATE TO_DATE BUSINESS_DAYS
    01-AUG-96 15-AUG-96 11

  • I want to get number of days in the month I've chosen from Timeline slicer.

    I want to get number of days in the month
    I've chosen from Timeline slicer,
    does anyone know how to do?
    The problem I want to solve is to divide
    the number of customer visits as a salesman
    made during a month by the number of
    days in the month.

    Excel 2013 Pro Plus with PowerPivot.
    Count working days per month
    considering weekends and holidays.
    With help from book:
    "Building Data Models with PowerPivot"
    by Alberto Ferrari and Marco Russo.
    Easy. Not.
    http://www.mediafire.com/view/rw78t1y3bg8vm0c/04_10_15.xlsx

Maybe you are looking for

  • Date Usage

    I've been noticing with interest the date problems encountered with Date and Calendar objects. It seems like most ways to set a Date are Depricated. I've been using longs in C for years as I'm not interested in time values or adding Dates. Aside from

  • XML reports show in XML format instead of Defult output PDF in R12

    I am facing a problem in XML report in oracle R12 , when I am running the report ,it through warning msg and output is coming in XML format instead of PDF . Please let me know the solution. Zulqarnain

  • Making size of photos fill entire top of screen

    I just got a contract to make changes to a layout my client has abandoned. I made a few changes to the CSS file, converted the site to a PHP template system, as well as updated the logo. After I made the changes, the height of the pictures changed. I

  • Problem in Retriving records

    i m callin a session bean from a jSp page,actually the constructor of sesssion bea,this calls the ejb create of entity bean Data is going in database,but only once i restart browser all data is available ,why not just by clicking the link of view. Th

  • Which is best Adobe product for me

    I have recently purchased a touch screen desk top computer. On my old system I was using Adobe Photoshop starter edition 3.2. What would be the best Adobe photoshop for me to purchase for home use & to be able to transfer my existing photos to?