Finding the difference in no. of days between 2 dates

Finding the difference in no. of days between 2 dates

http://search.java.sun.com/Search/java?col=javafrm&qp=%2Bforum%3A54&qt=days+difference&x=12&y=11

Similar Messages

  • How do you find the difference in no. of days between 2 dates?

    How do you find the difference in no. of days between 2 dates ?

    There are 2 way to solve this: using java.util.GregorianCalendar or java.util.Date (like jesper1 suggested), depending what kind of solution You need:
            GregorianCalendar gc1 = new GregorianCalendar(2001, 01, 01, 23, 00, 00);
            GregorianCalendar gc2 = new GregorianCalendar(2001, 01, 03, 10, 00, 00);
            // 1st way using GregorianCalendar
            int diff1 = gc1.get(GregorianCalendar.DATE) - gc2.get(GregorianCalendar.DATE);
            System.out.println("Differnce: " + diff1);
            // 2nd way using Date
            int diff2 = (int)(gc1.getTime().getTime() - gc2.getTime().getTime()) / (24 * 60 * 60 * 1000);
            System.out.println("Differnce: " + diff2);Note: There are 2 days between the given dates, but exactly 1 day and 11 hours.
    The first solution returns "-2", the second returns "-1".
    (... and a 4th posting also won't help ...)

  • Query to find the difference between the last date and the second to the last date

    Hi all,
    Hope all is well.
    I am working on the following problem because I am trying to improve my MS SQL skills. But I am stuck at the moment and I wonder if you could provide some assistance please. Here is the issue:
    Table 1: Dividends
    divId
    ExDate
    RecordDate
    PayDate
    Amount
    Yield
    symId
    1
    2013-02-19
    2013-02-21
    2013-03-14
    0.23
    0.00000
    3930
    2
    2012-11-13
    2012-11-15
    2012-12-13
    0.23
    0.00849
    3930
    3
    2012-08-14
    2012-08-16
    2012-09-13
    0.20
    0.00664
    3930
    4
    2012-05-15
    2012-05-17
    2012-06-14
    0.20
    0.00662
    3930
    5
    2012-02-14
    2012-02-16
    2012-03-08
    0.20
    0.00661
    3930
    6
    2011-11-15
    2011-11-17
    2011-12-08
    0.20
    0.00748
    3930
    7
    2011-08-16
    2011-08-18
    2011-09-08
    0.16
    0.00631
    3930
    8
    2011-05-17
    2011-05-19
    2011-06-09
    0.16
    0.00653
    3930
    9
    2011-02-15
    2011-02-17
    2011-03-10
    0.16
    0.00594
    3930
    10
    2010-11-16
    2010-11-18
    2010-12-09
    0.16
    0.00620
    3930
    11
    2010-08-17
    2010-08-19
    2010-09-09
    0.13
    0.00526
    3930
    12
    2010-05-18
    2010-05-20
    2010-06-10
    0.13
    0.00455
    3930
    13
    2010-02-16
    2010-02-18
    2010-03-11
    0.13
    0.00459
    3930
    Table 2: Tickers
    symId
    Symbol
    Name
    Sector
    Industry
    1
    A
    Agilent Technologies Inc.
    Technology
    Scientific & Technical Instruments
    2
    AA
    Alcoa, Inc.
    Basic Materials
    Aluminum
    3
    AACC
    Asset Acceptance Capital Corp.
    Financial
    Credit Services
    4
    AADR
    WCM/BNY Mellon Focused Growth ADR ETF
    Financial
    Exchange Traded Fund
    5
    AAIT
    iShares MSCI AC Asia Information Tech
    Financial
    Exchange Traded Fund
    6
    AAME
    Atlantic American Corp.
    Financial
    Life Insurance
    7
    AAN
    Aaron's, Inc.
    Services
    Rental & Leasing Services
    8
    AAON
    AAON Inc.
    Industrial Goods
    General Building Materials
    9
    AAP
    Advance Auto Parts Inc.
    Services
    Auto Parts Stores
    10
    AAPL
    Apple Inc.
    Technology
    Personal Computers
    11
    AAT
    American Assets Trust, Inc.
    Financial
    REIT - Office
    12
    AAU
    Almaden Minerals Ltd.
    Basic Materials
    Industrial Metals & Minerals
    I am trying to check the last date (i.e. max date) and also check the penultimate date (i.e. the second to the last date).  And then find the difference between the two (i.e. last date minus penultimate
    date).
    I would like to do that for each of the companies listed in Table 2: Tickers.  I am able to do it for just one company (MSFT) using the queries below:
    SELECT
    [First] = MIN(ExDate),
    [Last] = MAX(ExDate),
    [Diff] = DATEDIFF(DAY, MIN(ExDate), MAX(ExDate))
    FROM (
    SELECT TOP 2 Dividends.ExDate
    FROM Dividends, Tickers
    WHERE Dividends.symId=Tickers.symId
    AND Tickers.Symbol='MSFT'
    ORDER BY ExDate DESC
    ) AS X
    Outputs the following result:
    First
    Last
    Diff
    2012-11-13
    2013-02-19
    98
    But what I would like instead is to be able to output something like this:
    Symbol
    First
    Last
    Diff
    MSFT
    2012-11-13
    2013-02-19
    98
    AAN
    2012-11-13
    2012-12-14
    1
    X
    2012-11-13
    2012-12-14
    1
    Can anyone please let me know what do I need to add on my query in order to achieve the desired output?
    Any help would be greatly appreciated.
    Thanks in advance. 

    Could you try this?
    create table Ticker (SymbolId int identity primary key, Symbol varchar(4))
    insert into Ticker (Symbol) values ('MSFT'), ('ORCL'), ('GOOG')
    create table Dividend (DividendId int identity, SymbolId int constraint FK_Dividend foreign key references Ticker(SymbolId), ExDate datetime, Amount decimal(18,4))
    insert into Dividend (SymbolId, ExDate, Amount) values
    (1, '2012-10-1', 10),
    (1, '2012-10-3', 1),
    (1, '2012-10-7', 7),
    (1, '2012-10-12', 2),
    (1, '2012-10-23', 8),
    (1, '2012-10-30', 5),
    (2, '2012-10-1', 10),
    (2, '2012-10-6', 1),
    (2, '2012-10-29', 7),
    (3, '2012-10-1', 22),
    (3, '2012-10-3', 21),
    (3, '2012-10-7', 3),
    (3, '2012-10-12', 9)
    WITH cte
    AS (SELECT t.Symbol,
    d.ExDate,
    d.Amount,
    ROW_NUMBER()
    OVER (
    partition BY Symbol
    ORDER BY ExDate DESC) AS rownum
    FROM Ticker AS t
    INNER JOIN Dividend AS d
    ON t.SymbolId = d.SymbolId),
    ctedate
    AS (SELECT Symbol,
    [1] AS maxdate,
    [2] AS penultimatedate
    FROM cte
    PIVOT( MIN(ExDate)
    FOR RowNum IN ([1],
    [2]) ) AS pvtquery),
    cteamount
    AS (SELECT Symbol,
    [1] AS maxdateamount,
    [2] AS penultimatedateamount
    FROM cte
    PIVOT( MIN(Amount)
    FOR RowNum IN ([1],
    [2]) ) AS pvtquery)
    SELECT d.Symbol,
    MIN(MaxDate) AS maxdate,
    MIN(penultimatedate) AS penultimatedate,
    DATEDIFF(d, MIN(penultimatedate), MIN(MaxDate)) AS numberofdays,
    MIN(MaxDateAmount) AS maxdateamount,
    MIN(penultimatedateAmount) AS penultimatedateamount,
    MIN(MaxDateAmount) - MIN(penultimatedateAmount) AS delta
    FROM ctedate AS d
    INNER JOIN cteamount AS a
    ON d.Symbol = a.symbol
    GROUP BY d.Symbol
    ORDER BY d.Symbol
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers.
    Thanks!
    Aalam | Blog (http://aalamrangi.wordpress.com)

  • Hi, i want  to find the difference in days of two students Date Of Birth

    hi, i want to find the difference in days of two students Date Of Births
    how can i find.
    please help me

    i didn't find what u saidLet me help you:
    http://onesearch.sun.com/search/onesearch/index.jsp?qt=difference+between+dates&subCat=siteforumid%3Ajava54&site=dev&dftab=siteforumid%3Ajava54&chooseCat=javaall&col=developer-forums

  • Need to find the Difference between two table

    Hello ,
    I have stucked in program as below scenario:-
    I have two tables of huge data of same structure in a same schema.I need to find the difference exact values in tables.
    By using MINUS we can find the difference between two table ,i need to find the what exact difference in the there values with colunm and value at that column.
    Example TableA
    Col1 col2 col3 col4 col5.... col50
    10 ABC 2001 EE 444 TT
    40 XYZ 3002 RR 445 TT3
    80 DEF 6005 YY 446 YY8
    TableB
    Col1 col2 col3 col4 col5.... col50
    10 ABC 2001 EE 444 TT
    40 XYZ 3002 RR 445 TT3
    81 DEF 6005 Yu 447 YY8
    I need to the out put like this :-
    The Diffence between two table is
    TableA.COL1=80 TableB.Col1=81, Different
    TableA.Col4=YY TableB.col4=Yu,Different
    TableA.Col5=446TableB.col5=447,Different
    Please suggest me to write the pl/sql program for the same
    thanx in advance
    KK

    Thanx friends for all your efforts
    I have a sample code for the same,this will compare the two tables for single row in each table .
    what r the modification needed for the multiple rows of values in the two tables??
    Please suggest!!
    CREATE OR REPLACE PROCEDURE test_compare
    IS
    TYPE t_col
    IS
    TABLE OF VARCHAR2 (30)
    INDEX BY PLS_INTEGER;
    l_col t_col;
    j NUMBER := 0;
    l_sql VARCHAR2 (2000);
    col1 VARCHAR2 (30);
    col2 VARCHAR2 (30);
    val1 NUMBER;
    val2 NUMBER;
    status VARCHAR2 (30);
    CURSOR c1
    IS
    SELECT column_id, column_name
    FROM all_tab_columns
    WHERE table_name = 'TEST1';
    BEGIN
    FOR i IN c1
    LOOP
    j := j + 1;
    l_col (j) := i.column_name;
    END LOOP;
    FOR k IN 1 .. j
    LOOP
    l_sql :=
    'SELECT '
    || ''''
    || l_col (k)
    || ''''
    || ', '
    || 'TEST2.'
    || l_col (k)
    || ', '
    || ''''
    || l_col (k)
    || ''''
    || ', '
    || 'TEST1.'
    || l_col (k )
    || ', '
    || 'DECODE(TEST2.'
    || l_col (k)
    || ' -TEST1.'
    || l_col (k)
    || ', 0, ''NO CHANGE'', ''CHANGED'') FROM TEST2, TEST1';
    EXECUTE IMMEDIATE l_sql INTO col1, val1,col2, val2, status;
    IF status = 'CHANGED'
    THEN
    DBMS_OUTPUT.put_line( 'TEST2.'
    || col1
    || '='
    || val1
    || ', TEST1.'
    || col2
    || '='
    || val2
    || ', '
    || status);
    END IF;
    END LOOP;
    EXCEPTION
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.put_line ('Error:- ' || SQLERRM);
    END;
    /

  • How to find the difference in object definition between two databases

    Hi,
    Can any one suggest me how to find the difference in object definition between two different databases. Is there any tool or by OEM? If so how?
    Regards
    Naveen

    this link may be helpful...
    http://www.dbspecialists.com/scripts.html

  • I want to find the difference(duration) between logon and logoff time?

    i want to find the difference(duration) between logon and logoff time of below table?
    can any one tell the query to find using self join?
    USR     LOGON_TIME     LOGOFF_TIME
    HR     31-AUG-04 03.04.04.000000 AM     -
    HR     - 31-AUG-04 03.04.14.000000 AM
    Edited by: 794244 on Nov 1, 2010 10:47 PM

    No selfjoin, just analytical functions.
    CREATE TABLe log_time
    (username varchar(20),
    LOGON_TIME timestamp,
    LOGOFF_TIME timestamp);
    insert into  log_time (username,LOGON_TIME,LOGOFF_TIME) values ('HR',sysdate,null);
    insert into  log_time (username,LOGON_TIME,LOGOFF_TIME) values ('HR',null,sysdate+1/38);
    insert into  log_time (username,LOGON_TIME,LOGOFF_TIME) values ('HR',sysdate+2,null);
    insert into  log_time (username,LOGON_TIME,LOGOFF_TIME) values ('HR',null,sysdate+2+14/20);
    commit;
    SELECT username,logon_time,logoff_time, my_logoff_time, my_logoff_time -logon_time,
           time_to_sort
    FROM (
            SELECT username,logon_time, logoff_time,
                   LEAD(logoff_time,1,logon_time) OVER (PARTITION BY username ORDER BY time_to_sort) my_logoff_time,
                   time_to_sort
            FROM (SELECT username,logon_time,logoff_time,NVL(logon_time,logoff_time) time_to_sort
                  FROM log_time)
    where LOGON_TIME is not null     
    ORDER BY  time_to_sort; 
    USERNAME     LOGON_TIME     LOGOFF_TIME     MY_LOGOFF_TIME     MY_LOGOFF_TIME-LOGON_TIME     TIME_TO_SORT
    HR     02.11.10 11:34:56.000000000          02.11.10 12:12:50.000000000     0 0:37:54.0     02.11.10 11:34:56.000000000
    HR     04.11.10 11:34:56.000000000          05.11.10 04:22:56.000000000     0 16:48:0.0     04.11.10 11:34:56.000000000But, if that code which fills that table should better UPDATE than INSERT. You can cover much more issues. (e.g the DB crashes and you get 2 logon but no logoff in a sequence and.....)
    -- andy

  • An anyone help me to find the difference and relation between the following

    Hi,
    can anyone help me to find the difference and relation between the following methods of Swing :
    a) validate()
    b) invalidate()
    c) revalidate()
    d) repaint()

    You'd be far ahead by opening up the API and Java turorial and your course book and learning for yourself, rather than, asking other to do your homework for you.
    But if you have andwers already to go, then post them and ask if you have drawn appropriate conclusions.

  • Find the difference between two columns in an ssrs matrix ? MSCRM

    Hi All,
    I am working in reporting part of our project (On-line MSCRM 2013) & in reporting services.
    I am trying to create report using fetch xml based. Below is the snap what we required the result.
    Kindly help me, how to get the difference in both column. (Its a matrix table where year is grouped).
    We need difference between both year Like (Plan Revenue of 2013 & Plan Revenue of 2014 difference in Plan Revenue Diff section) and same for Actual
    Revenue.
    https://social.microsoft.com/Forums/en-US/054d5ca4-0d38-4dc6-84a8-88866cc228fe/find-the-difference-between-two-columns-in-an-ssrs-matrix-mscrm?forum=crmdevelopment
    Thanks,
    Mohammad Sharique

    Hi Bro,
    I used parametrized option for year and done the report,Currently we are getting values in Difference column now i want to show
    that value in percentage. How can we show the percentage based on that value. Means i want to show the Difference in Percentage. 
    Kindly help me i tried but getting some issue. Below i am mentioning the code and snap with result.
    Below expression using to showing Plan Revenue in Percentage for year.
    =
    Sum(IIF(Fields!new_year.Value =Parameters!StartYear.Value,cdec(Fields!new_planrevenueValue.Value/1000), cdec(0)))
    - Sum(IIF(Fields!new_year.Value =Parameters!EndYear.Value,cdec(Fields!new_planrevenueValue.Value/1000), cdec(0)))
    /IIF(Sum(IIF(Fields!new_year.Value = Parameters!StartYear.Value,cdec(Fields!new_planrevenueValue.Value/1000), cdec(0)))>0,
    (Sum(IIF(Fields!new_year.Value = Parameters!StartYear.Value,cdec(Fields!new_planrevenueValue.Value/1000), cdec(0))))
    ,1)
    )*100))
    Result issue is as below in snap with highlighted in red colour.
    Kindly help me on this issue also :)

  • Find the difference between loading and registering the drivers..

    Dear Sir..
    Could you please help me to find the difference between two activities..
    1.Loading the drivers
    2.Registering the drivers
    What's the difference between loading and registeing the drivers and what activities take place by the JVM to do it all.

    Dear Sir..
    Could you please help me to find the difference
    between two activities..
    1.Loading the drivers
    2.Registering the drivers
    What's the difference between loading and registeing
    the drivers and what activities take place by the JVM
    to do it all.You load a class - it isn't specific to a driver.
    That is part of java - not JDBC.
    Normally JDBC drivers register themselves when the class is loaded. This is specific to the driver and has nothing to do with a user of the driver. It is only a concern to someone who must implement a driver.

  • How to find the difference between Project costs & Cost center costs?

    Hi all,
    Can you please explain me ? What is project Cost & Cost center cost and which are the tables having those fields of project cost & cost center Costs? And how to find the difference between their costs ? And please give me the functional Idea about it?
    Thanking you all in Advance...
    Regards,
    Chandru

    Hi,
    goto table COSP:
    1) object-no. beginning with 'KS' refer to cost-centre
       example: 'KSKOKA4711'
       with KS, KOKA = controlling area and 4711 = cost centre
    2) OBJNR beginning with 'PR' refer to projects / WBS-element
       example PR00001234
    Message was edited by: Andreas Mann

  • Extract Time from date and Time and Need XLMOD Funtion to find the Difference between Two Time.

    X6 = "1/5/15 5:16 AM" & NOW ....................difference by Only Time
    not date
    X6 date and Time will be changing, Its not Constant
                Dim myDateTime As DateTime = X6
                Dim myDate As String = myDateTime.ToString("dd/MM/yy")
                Dim myTime As String = myDateTime.ToString("hh:mm tt")
                Dim myDateTime1 As DateTime = Now
                Dim myDate1 As String = myDateTime1.ToString("dd/MM/yy")
                Dim myTime1 As String = myDateTime1.ToString("hh:mm tt")
    Need to use this function to find the Difference between Two Time. due to 12:00 AM isuue
    Function XLMod(a, b)
        ' This replicates the Excel MOD function
        XLMod = a - b * Int(a / b)
    End Function
    Output Required
     dim dd  = XLMod(myTime - myTime1)
    Problem is myTime & myTime1 is String Need to convert them into Time, Later use XLMOD Funtion.

    Induhar,
    As an addendum to this, I thought I'd add this in also: If you have two valid DateTime objects you might consider using a class which I put together a few years ago
    shown on a page of my website here.
    To use it, just instantiate with two DateTime objects (order doesn't matter, it'll figure it out) and you'll then have access to the public properties. For this example, I'm just showing the .ToString method:
    Option Strict On
    Option Explicit On
    Option Infer Off
    Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles MyBase.Load
    Dim date1 As DateTime = Now
    Dim date2 As DateTime = #1/1/1970 2:35:00 PM#
    Dim howOld As New Age(date1, date2)
    MessageBox.Show(howOld.ToString, "Age")
    Stop
    End Sub
    End Class
    I hope that helps, if not now then maybe at some point in the future. :)
    Still lost in code, just at a little higher level.
      Thanx frank, can use this in Future....

  • Function Module to find the Difference between two times.

    Hi All,
    Wud you plz let me know the Function Module to find the Difference between two times.
    Input Time1( Hours:Minutes) Time2 ( Hours:Minutes)
    Need Output in Hours:Minutes only . ( No seconds Needed )
    Ex :
    Input :
           06:00 to 18:00 Output : 12:00
    and  20:00 to 06:00 Output: 10:00 with +ve sign only. No -ve sign.
    Thanks,
    N.L.Narayana

    check this .
    data : p_timel like sy-uzeit,
           p_timeh like sy-uzeit,
           diff like sy-uzeit,
           di(8) type c .
           p_timel = '200000'.
           p_timeh = '060000'.
           diff = p_timeh - p_timel.
           concatenate diff+0(2) ':' diff+2(2) into di.
           write:/ di.
    also check for this.
           p_timel = '060000'.
           p_timeh = '180000'.
    see if this can be implemented in ur code .
    or else  u can try with  Fm L_TO_TIME_DIFF passing startdate enddate starttime endtime with UOM as MIN
    hope this helps regards,
    vijay

  • How to find the difference between 2 time values in Java

    hi all,
    i have 2 time values
    String time1="6:20";
    String time2="21:30"
    How to find the difference between 2 times in Java?
    pls help
    thanx in advance....

    Calculating Java dates: Take the time to learn how to create and use dates
    Working in Java time: Learn the basics of calculating elapsed time in Java
    Formatting a Date Using a Custom Format
    Parsing a Date Using a Custom Format

  • BCT - how to find the difference between installed BCT and the newest BCT?

    Hi,
    How do I find the difference between installed BCT and the newest BCT?
    or find a description of the newest BCT?
    Thank you.
    - Gunnar

    Hi,
    Thank you for your answer.
    I am aware of the possibilities you mention.
    I am looking for a way to find the parts of the business content that has been modified since I installed our current version WITHOUT installing anything.
    That is for example:
    If F&R business content has been moved from 3.x technology to 7.0
    If there is changes to the F&R content at all
    -> if our current version of business content already contains the newest version of Business Content for F&R, then it is not a prerequirement to an F&R project that we update business content.
    The possibility to see that the only changes might be in the area of SAP HCM ...
    Thank you.
    - Gunnar

Maybe you are looking for

  • O/p of alv grid

    hi all, i want the o/p of one alv report as the o/p of tcode MBLB. how can i assign the fields like that. PLZ explain me with simple coding. regards Nilabichi

  • Data replacement in stmedit WFP sample.

    Hi all ! I have a problem with testing stmedit WFP sample. I have configured parameters such as       EditInline      = 0 (out-of-band)       StringToFind    = "rainy"       StringToReplace = "sunny"       InspectionPort  = 1004       InspectOutbound

  • Setting a session bean

    How do i set a session bean in my JSF action? I have defined this session bean in my faces-config.xml file: <managed-bean> <managed-bean-name>SelectedHistoryRecord</managed-bean-name> <managed-bean-class>com.myco.nps_history.model.NPSHistoryRecord</m

  • WAAS 4.1.1c - Optimized CIFS Sessions

    I have 2 remote devices. Using the CM and looking at Dsshboard > Devices > Device1, then the Acceleration tab, I see "Insufficient data to plot the chart" for Optimized CIFS Sessions. I've got 25+ users at one location, and 3 users at the other. Shou

  • Performance point service for SharePoint List

    Hi All, I've a requirement to create Performance Point service to display in the SharePoint List. List contact single line of text columns. So i would like to know whether there is any possibilities to  utilities this PPS for this SharePoint List. Pl