Comparing date

hi ,
I am writting a program in which i take 2 user input for the date in string format ie dd/mm/yyyy.,
1st is taking loan date
2nd is return date
-> now i need to compare them if they are the same date.
-> if they are different . 2/10/2006 and 6/10/2006
i need to increament the date and calculate the charge for the period.
i am doing it in the following manner
String loanDate = new String (stdin.nextLine());
StringTokenizer loanDateString = new StringTokenizer(loanDate,"/");
day = Integer.parseInt(loanDateString.nextToken());
month = Integer.parseInt(loanDateString.nextToken())-1;
year = Integer.parseInt(loanDateString.nextToken());
loandate = Calendar.getInstance();
loandate.set(year,month,day);
String loanReturnDate = new String (stdin.nextLine());
StringTokenizer returnDateString = new StringTokenizer(loanReturnDate,"/");
day = Integer.parseInt(returnDateString.nextToken());
month = Integer.parseInt(returnDateString.nextToken())-1;
year = Integer.parseInt(returnDateString.nextToken());
returnDate = Calendar.getInstance();
returnDate.set(year,month,day);
if(loandate.equals(returnDate)) {
// calculate cost
else {        
while (returnDate.after(loandate)){
//calculate cost
// increament the date
b ut the problem is in "if condition" it never returns true as there is always a time difference ....how do i compare only date and not the time.

When you post code, please wrap it in [code] tags so it's legible.
-> if they are different . 2/10/2006 and 6/10/2006
i need to increament the date and calculate the
charge for the period.What do you mean "increment the date"? I can see what that could mean, but how is that relevant to figuring out the interval?
> String loanDate = new String (stdin.nextLine());That "new String" is unnecessary, assuming that nextLine() returns a String which it probably does.
> StringTokenizer loanDateString = new StringTokenizer(loanDate,"/");
>
day = Integer.parseInt(loanDateString.nextToken());
month = Integer.parseInt(loanDateString.nextToken())-1;
year = Integer.parseInt(loanDateString.nextToken());(etc) Rather than doing this you might want to consider using a java.text.SimpleDateFormatter to do the parsing for you.
> loandate = Calendar.getInstance();Having two variables whose names differ only in the case of a single letter is ugly, hard to maintain, and bug-prone.
ut the problem is in "if condition" it never returns
true as there is always a time difference ....how do
i compare only date and not the time.You could compare just the int fields of the year, month and day, and not use Calendar objects at all. Since you're doing the parsing yourself you might as well use them.
Another option however is just to compare whether the return is after the start or not. Use the .after() or before() method (on either Calendar or java.util.Date).
So ultimately I think you should:
1) use java.text.SimpleDateFormat to do the formatting, and then store two Date objects
2) compare the two Date objects using before() or after(), like this:
if (return.after(start))

Similar Messages

  • Compare data in R/3 with data in a BW Cube after the daily delta loads

    Hi Friends,
    How can I compare data in R/3 with data in a BW Cube after the daily delta loads? Are there any standard procedures for checking them or matching the number of records?

    Hi Sunil,
    If you want to check the records daily instead of checking the data in R/3 manually ......
    You can try this...
    If you have staging DSO(level 1) that means whatever data is in source system load it to Staging DSO without any routines or any modifications.
    Now load this DSO data to Cube or DSO(level 2) as per your requirement with routines etc.
    Now Staging DSO contains Source system data.
    Now the level 2 Cube or DSO contains BW data with some modifications.
    Now create a Multiprovider based on level 1 and level 2 data targets.
    Now create a report on which keyfigures you want to test the data.
    In Multiprovider there is a field called 0infoprovider in data packet dimension.
    you can drag this infoprovider to the columns and restict your keyfigures with level 1 and level 2 data targets.
    In the first column you can see the level 1 DSO data ( source system data),in the 2nd column you can see the BW data.
    Now create a formula which gives the diffrence b/n level 1 and level2.
    that is R/3 data - BW data.
    If the diffrence is zero both R/3 and BW data are same.
    if the diffrence is not eqaul to zero check whether any routine is there or not.

  • Comparing data b/w biw and oltp

    hi
    Could some one can halp me how to compare data between biw and oltp system.which has been extracted.
    Thank for your precious time spent to help me in learning.
    Thanks,
    Jagadeesh

    Jagadish,
    It is not always all extracted data are coming from one standard table and comparison is easy. most of the time from multiple tables. There are couple of things you can do.
    1. If you know any R3 functionals you can inquire about reports available that produce the same kind of column groupings.
    2. If no one exists or do not get much help from them, and if you have SQ01 access in R3 you can create a query to bring the same columns fromcorresponding tables (This is a harder because you need access and need to findout from where data is coming from though info is available in help.sap.com).
    3. more practical would be select a small subset of data, with right filters in your selection columns of the info package and extract data, at the same time use the same selection in RSA3 (R3 side) to extract data and compare. This should tell you whether what you have in R3 is matching with the extracted data.
    4. After your transformations you can compare the same with your info provider (cube or ODS) contents as well.
    hope this helps,
    Award points if useful.
    Alex (Arthur Samson)

  • Comparing data in different resultsets

    Hi everybody!
    I am working on an web application involving some EAI, as a requirement i need to compare data from two different sources (databases to be precise) and fill a XML based on certain rules. I wish to know if there is a way to compare two ResultSet objects (with almost similar data) directly, or the only way to do is compare each value seperately.
    Also please suggest from efficiency point of view if its viable to store data from resultSet to a certain struc kind of object and then comparing, as it would involve lots of overhead compared to directly comparing the two resultsets.
    TIA
    Abhishek

    i have to compare various columns of each row and assign flags in output xml as to note if data is inconsistant, though i am taking measures so as to get the rows in the same order in both result sets, but the primary purpose of this comparison is indeed to check data integrity between both the sources.

  • Table_comparison - how to compare data at a high level

    Hi,
    I have to do data validation at a high level between two tables that I am loading.
    I am trying to use table_comparion transform but the problem is that my target table is at a much lower level than at which I want to compare data. So it has many more columns (both key and data fields) than what I want to compare.
    Does the output of query transform ( which I am using as input into table_comparion) be in the exact same format as comparion table? If not, then can somebody suggest me something else.
    Or how can I compare output of two query transforms ?
    Thanks,
    Saurabh Bansal

    Dear Saurabh,
    Not sure if you have already got the solution to this. If yes please close the thread.
    If not, i would suggest you can use the validation rule to compare the two tables and then based on the PASS or FAIL result can check what needs to be done on the output.
    Do post back if you have got the solution or you need any furthur help or else close the question.
    regards,
    Den

  • Compare data from a table

    Hello, I am trying to compare data from one and the same table. In short I have:
         NAME     DTM     CHARGE
         Atanas     8/18/2012 9:33:23 AM     100
    Atanas     8/18/2012 9:33:23 AM     101
         Niki     8/18/2012 9:33:43 AM     200
         Niki     8/17/2012 9:34:10 AM     100
    Niki     8/18/2012 9:33:43 AM     201
         Niki     8/17/2012 9:34:10 AM     101
         Atanas     8/17/2012 9:34:29 AM      50
    Atanas     8/17/2012 9:34:29 AM      51
         Joro     8/18/2012 12:10:12 PM 400
         Joro     8/17/2012 12:10:21 PM 300
    Joro     8/18/2012 12:10:12 PM 401
         Joro     8/17/2012 12:10:21 PM 301
    And I want to sum CHARGE for each DTM for each NAME and present the difference in an additional column, the output should be like that:
    NAME     DTM     CHARGE DTM CHARGE DIFFERENCE
         Atanas     8/17/2012 9:33:23 AM     101 8/18/2012 9:33:23 AM 201 - 100
    Niki     8/17/2012 9:33:23 AM     201 8/18/2012 9:33:23 AM 401 - 200
    Joro     8/17/2012 9:33:23 AM     601 8/18/2012 9:33:23 AM 801 200
    the DTM will be always /sysdate - 2/ and /sysdate - 1/,
    Thanks in advance!

    It is not clear what you are trying to do, but it looks like:
    with sample_table as (
                          select 'Atanas' name,to_date('8/18/2012 9:33:23 AM','mm/dd/yyyy hh:mi:ss am') dtm,100 charge from dual union all
                          select 'Atanas',to_date('8/18/2012 9:33:23 AM','mm/dd/yyyy hh:mi:ss am'),101 from dual union all
                          select 'Niki',to_date('8/18/2012 9:33:43 AM','mm/dd/yyyy hh:mi:ss am'),200 from dual union all
                          select 'Niki',to_date('8/17/2012 9:34:10 AM','mm/dd/yyyy hh:mi:ss am'),100 from dual union all
                          select 'Niki',to_date('8/18/2012 9:33:43 AM','mm/dd/yyyy hh:mi:ss am'),201 from dual union all
                          select 'Niki',to_date('8/17/2012 9:34:10 AM','mm/dd/yyyy hh:mi:ss am'),101 from dual union all
                          select 'Atanas',to_date('8/17/2012 9:34:29 AM','mm/dd/yyyy hh:mi:ss am'),50 from dual union all
                          select 'Atanas',to_date('8/17/2012 9:34:29 AM','mm/dd/yyyy hh:mi:ss am'),51 from dual union all
                          select 'Joro',to_date('8/18/2012 12:10:12 PM','mm/dd/yyyy hh:mi:ss am'),400 from dual union all
                          select 'Joro',to_date('8/17/2012 12:10:21 PM','mm/dd/yyyy hh:mi:ss am'),300 from dual union all
                          select 'Joro',to_date('8/18/2012 12:10:12 PM','mm/dd/yyyy hh:mi:ss am'),401 from dual union all
                          select 'Joro',to_date('8/17/2012 12:10:21 PM','mm/dd/yyyy hh:mi:ss am'),301 from dual
    select  nvl(s1.name,s2.name) name,
            s1.dtm,
            s1.charge,
            s2.dtm,
            s2.charge,
            s2.charge - s1.charge diff
      from      (
                 select  name,
                         dtm,
                         sum(charge) charge
                   from  sample_table
                   where dtm >= trunc(sysdate) - 1
                     and dtm <  trunc(sysdate)
                   group by name,
                            dtm
                ) s1
            full join
                 select  name,
                         dtm,
                         sum(charge) charge
                   from  sample_table
                   where dtm >= trunc(sysdate)
                     and dtm <  trunc(sysdate) + 1
                   group by name,
                            dtm
                ) s2
              on s1.name = s2.name
    NAME   DTM           CHARGE DTM           CHARGE       DIFF
    Atanas 17-AUG-12        101 18-AUG-12        201        100
    Niki   17-AUG-12        201 18-AUG-12        401        200
    Joro   17-AUG-12        601 18-AUG-12        801        200
    SQL> SY.

  • Comparing data from two tables

    My PL/SQL is very limited, however, I need to write some code that compares data stored in two different Oracle tables and then writes the differences to a third table. Both tables have primary keys that I will use to ensure I am comparing like for like. These tables could be large.
    Any help on the best way to do this, or any code examples would be very appreciated.

    One fairly efficient way of doing this is with set operators. The following code is untested - but looks right ;). It also assumes you want to know the provenance of the rows; if not, just zap the literal from each SELECT statement.
    INSERT INTO diff_tab SELECT * FROM
      ( (SELECT 'tab1nottab2' AS provenance, t1.col1, t1.col2 FROM tab1 t1
         MINUS
         SELECT 'tab1nottab2', t2.col_a, t2.col_b FROM tab2 t2)
         UNION ALL
         (SELECT 'tab2nottab1', t2.col_a, t2.col_b FROM tab2 t2
          MINUS
          SELECT 'tab2nottab1', t1.col1, t1.col2 FROM tab1 t1)
    /Cheers, APC

  • How to compare date which is greatest date

    iam new to sql
    how to compare date which date is greatest date with example
    can i use to_char to compare date
    SELECT eno, ename, GREATEST (TBLE.MAX1, TBLE.MAX2) recent_date "
                   FROM (SELECT TBLA.eno, TBLA.ename, "
                   MAX (TO_CHAR (TBL.date1, 'MM/DD/YYYY HH24:MI') "
                   ) MAX1, "
                   MAX (TO_CHAR (TBL.date2, 'MM/DD/YYYY HH24:MI') "
                   ) MAX2 "
                   FROM dual TBL, dual2 TBLA
    in above query if any one of the date having null value then recent_date is showing 'null'
    and also it showing wrong value
    example
    date1='08-22-2009' and date2='01-23-2010' then it showing wrong recent_datel ike='08-22-2009'
    as according my knowledge it is comparing with month it sholud not be like this wat i have to do pls explain with example my o/p should come for recent_date like =''01-23-2010''
    Edited by: user9112274 on Aug 27, 2010 5:31 AM

    Hi,
    there are numerous ways to compare dates, i give you some examples:
    with data_Sample as
    (select to_date('01-jan-2001','dd-mon-yyyy') d1, to_date('01-mar-2002','dd-mon-yyyy') d2, to_date('03-feb-2002','dd-mon-yyyy') d3 from dual)
    select greatest(d1,d2,d3) from data_Sample
    GREATEST(D1,D2,D3)
    3/1/2002
    with data_Sample as
    (select to_date('01-jan-2001','dd-mon-yyyy') d1 from dual union all
    select to_date('01-mar-2002','dd-mon-yyyy')   from dual union all
    select to_date('03-feb-2002','dd-mon-yyyy')  from dual)
    select max(d1) from data_Sample
    MAX(D1)
    3/1/2002
    declare
    d1 date :=to_date('01-jan-2001','dd-mon-yyyy');
    d2 date :=to_date('01-jan-2001','dd-mon-yyyy');
    begin
    if d1>d2 then
    dbms_output.PUT_LINE('d1 greater than d2');
    else
    dbms_output.PUT_LINE('d1 less or equql than d2');
    end if;
    end;
    output:
    d1 less or equal than d2now concerning your question:
    >
    can i use to_char to compare date
    >
    If you have date data types : don't convert them.
    if you have no choice, use something like:
    if to_char(d1,'YYYYMMDD') > to_char(d2,'YYYYMMDD') then
    else
    end if;Take care when you convert a date into a char format it becomes string comparison (with all it implies) (It's the reason why i've use an explicit mask format).

  • How to compare date and time together

    Hi,
    How to compare Date and Time together?
    For example in a database table there are two fields rundate and runtime.  I want to compare these two with perticular date and time in the program.  Like, I want to pull all the records where the records's date and time are less than a perticular date and time in the program.
    Hope the question is clear...
    Thanks.
    Kavita

    Hi Kavita
    There is no as such Date and Time Comparision FM in Standard SAP  But You can define your own like this
    <b>FUNCTION ZAV4_COMPAREDATETIME.
    ""Lokale Schnittstelle:
    *"  IMPORTING
    *"     REFERENCE(DATE1) TYPE  DATS
    *"     REFERENCE(TIME1) TYPE  TIMS
    *"     REFERENCE(DATE2) TYPE  DATS
    *"     REFERENCE(TIME2) TYPE  TIMS
    *"  EXPORTING
    *"     VALUE(TWOISMORETOPICAL) TYPE  C
      twoismoretopical = ''.
      if date2 > date1.
        twoismoretopical = 'X'.
      else.
         if date2 = date1 and time2 > time1.
           twoismoretopical = 'X'.
         endif.
      endif.
    ENDFUNCTION.</b>
    Regards
    Mithlesh

  • How to compare date with char

    hi
    i am having date from and date to feilds in my overtime element.i want to do the validation on these dates the the dates do not overlap or duplicated.the input value date from and date to are stored in database as varchar2 in the format yyyy/mm/dd 00:00:00. Now if i am trying to compare entered date with these dates i am getting literal does not match format string or date picture ends before....Can any body tell me what to do.
    Regards

    user10502390 wrote:
    hi
    i am having date from and date to feilds in my overtime element.i want to do the validation on these dates the the dates do not overlap or duplicated.the input value date from and date to are stored in database as varchar2 in the format yyyy/mm/dd 00:00:00. Now if i am trying to compare entered date with these dates i am getting literal does not match format string or date picture ends before....Can any body tell me what to do.
    RegardsPoint a) VERY BAD IDEA storing dates as VARCHAR2 on the database. It will only lead to corrupt data in the future.
    Point b) When comparing dates, you should compare them as DATE datatype as the database knows how to do comparisons against DATES. If you try and compare them as VARCHAR2 then you will most likely end up with incorrect comparisons.
    If you must have varchar2 storing of your dates/times (there's absolutely no reason to though)... you want...
    TO_DATE(:entered_date,'YYYY/MM/DD HH24:MI:SS') BETWEEN TO_DATE(DATEFROM,'YYYY/MM/DD HH24:MI:SS') AND TO_DATE(DATETO,'YYYY/MM/DD HH24:MI:SS')
    e.g.
    TO_DATE('20080815 13:23:33','YYYY/MM/DD HH24:MI:SS') BETWEEN TO_DATE(DATEFROM,'YYYY/MM/DD HH24:MI:SS') AND TO_DATE(DATETO,'YYYY/MM/DD HH24:MI:SS')

  • How manage two numbers files in the same screen to compare data

    Hello,
    I have two - 2 numbers files that I want to compare data between them in the same screen, How can I do that? Like in Excel you can compare two differente files in the same screen with the option windows cascade or something like that.
    Please Help Me.....

    First, turn off the abomination that is called "Full Screen" -- ported from the iPhone, land of tiny screens and single tasks.
    Then resize the first window to take up half the screen and place it on the left. Open the second spreadsheet and resize its window and place it on the right.
    Compare.

  • How to compare data between two tables?

    Hi,
    My team is trying to develop a SAP data migration tool (DMT) using ABAP.
    One of the functionalities in the DMT is to validate the data in the staging area against the loaded SAP data.
    The tables in the stagin area are customer tables (i.e. user-defined tables starting with Y, Z).
    How do I compare the data in the staging area against data that are loaded into SAP tables? Are there some built-in SAP functions to do this? Or, are there some better ways of doing this (e.g. instead of comparing against data in the SAP tables, we compare with some INTERNAL tables)?
    Any help would be greatly appreciated, thanks!

    Hi Kian,
    Use <b>SCMP</b> transaction to compare data between two tables and you can not use this for comparing internal tables.
    Thanks,
    Vinay

  • How to compare dates using javascript?

    Hi,
    I have to compare dates using javascript. The dates are in format "mm/dd/yy" for eg "10/09/06".
    I have written a script to compare the dates but the problem I 'm facing is with the year.
    For example if I compare "10/09/06" with "10/04/98", then "10/04/98" is coming out to be greater than "10/09/06" because it is considering year "98" to be greater than "06".
    Please advice/suggest.
    Thanks in advance...

    Dude, you're here in a Java forum, not in a Javascript forum. Those are two entirely different languages.
    The answer in Java is to use java.text.SimpleDateFormat to convert String to Date and use java.util.Date and/or java.util.Calendar to compare dates.

  • How to compare dates between two items

    Hello all,
    I am trying to compare dates in two items.
    The first item is a computation P45_PAGE_LOADED_TIME
    select sysdate from dual;
    This essentially keeps track of when the user opened the form. They are accessing data that may become obsolete while they are in the form.
    So we have a dynamic action that finds the last_update date from a table. This field is of type date. It is placed in a text field called P45_STATUS.
    We then have a notification which we want to fire when P45_PAGE_LOADED_TIME is before P45_STATUS. We tried the following condition
    declare
    least_date date;
    begin
    SELECT LEAST(TO_DATE(:P45_STATUS),TO_DATE(:P45_PAGE_LOADED_TIME)) into least_date
    from dual;
    if least_date = to_date(:P45_STATUS) then
    return false;
    else
    return true;
    end if;
    end;
    Any guidance would be most appreciated.
    Thanks

    Maybe your better off putting your anonymous block into a plsql function.
    A function that you can test. If it works in plsql then you must call it in APEX.
    I kinda get a headache when I see that least, to_date, to_date query (although I've seen worse :p)
    Make it like:
    create or replace function fun_least_date(in_status in varchar2,
                                                               in_page_loaded_time varchar2) return boolean
    is
      l_status date;
      l_page_loaded_time date;
      least_date date;
      l_return boolean;
    begin
      l_status := to_date(in_status, 'FORMAT MASK!!!');
      l_page_loaded_time := to_date(in_page_loaded_time, 'FORMAT MASK!!!!');
      least_date := least(l_status, l_page_loaded_time);
      if least_date = l_status then
        l_return := false;
      else
        l_return := true;
      end if;
      return l_return
    end fun_least_date;If your sure that your function is correct then use it as a condition for your dynamic action.
    Regards
    Nico
    ps: I haven't tested that function. Be aware that you most correctly enter the format mask you use in APEX. Also before APEX may know about these variables you should set a dynamic action on your items to always submit their value to the server when they change!!!

  • Compare date in SQL statement

    yup.. how can i compare date in SQL statement??
    pls give me a completed example.

    I'd think this is a formatting problem. Why not try:
    PreparedStatement ps = myConnection.prepareStatement(
    "SELECT * FROM Receipt WHERE to_date(Date) > ? ");
    ps.setDate(1,TodayDate);
    ResultSet rs = ps.executeQuery();
    HTH,
    Ken

  • Less Than operator not working, Greater Than operator works comparing dates

    I need to compare dates to conditionally display a row. If the DateDueJulian_ID5<= AsOfDate_ID47 display otherwise don't. I get all rows but if I reverse the logic >= the condition works and only displays the one matching row.
    I am using the Template Builder 10.1.3.4.1 and WORD 2007.
    Any help is appreciated!
    Thanks
    XML Source:
    <Header_Section_S3>
    <Delinquency_Report_ID225>DELINQUENCY NOTICE</Delinquency_Report_ID225>
    <VersionName_ID270>0001</VersionName_ID270>
    <Report_or_Video_Title_ID53></Report_or_Video_Title_ID53>
    <Remit_To_Text_ID68>Remit To:</Remit_To_Text_ID68>
    <RemitToAddressLine1_ID2>XXXXX</RemitToAddressLine1_ID2>
    <XX_XX_XX_ID259>2010-08-25</XX_XX_XX_ID259>
    <Date__ID258>Date</Date__ID258>
    <RemitToAddressLine2_ID5></RemitToAddressLine2_ID5>
    <RemitToAddressLine3_ID8></RemitToAddressLine3_ID8>
    <As_of_Date__ID46>As of Date</As_of_Date__ID46>
    <AsOfDate_ID47>2007-11-29</AsOfDate_ID47>
    <A_R_Delinquency_Notice_Detail_Join_S2>
    <DocVoucherInvoiceE_ID1>1897265</DocVoucherInvoiceE_ID1>
    <DateInvoiceJ_ID3>2007-10-11</DateInvoiceJ_ID3>
    <DateDueJulian_ID5>2007-12-10</DateDueJulian_ID5>
    <NameRemark_ID7></NameRemark_ID7>
    <AmountOpen_ID11></AmountOpen_ID11>
    <AddressNumber_ID17></AddressNumber_ID17>
    <UniqueKeyIDInternal_ID19></UniqueKeyIDInternal_ID19>
    <KAV_CustomerPONumber_ID23></KAV_CustomerPONumber_ID23>
    </A_R_Delinquency_Notice_Detail_Join_S2>
    <A_R_Delinquency_Notice_Detail_Join_S2>
    <DocVoucherInvoiceE_ID1>1897265</DocVoucherInvoiceE_ID1>
    <DateInvoiceJ_ID3>2007-10-11</DateInvoiceJ_ID3>
    <DateDueJulian_ID5>2007-11-10</DateDueJulian_ID5>
    <NameRemark_ID7></NameRemark_ID7>
    <AmountOpen_ID11></AmountOpen_ID11>
    <AddressNumber_ID17></AddressNumber_ID17>
    <UniqueKeyIDInternal_ID19></UniqueKeyIDInternal_ID19>
    <KAV_CustomerPONumber_ID23></KAV_CustomerPONumber_ID23>
    </A_R_Delinquency_Notice_Detail_Join_S2>
    RTF:
    <?for-each:Header_Section_S3?>
    <?if:DateDueJulian_ID5 <= AsOfDate_ID47?>
    <?DocVoucherInvoiceE_ID1?>
    <?DateDueJulian_ID5?>
    <?AsOfDate_ID47?>
    <?end if?>
    <?end for-each?>

    Found the solution! Use Date_Diff.
    <?if:xdoxslt:date_diff('d',DateDueJulian_ID5,AsOfDate_ID47,$_XDOLOCALE,$_XDOTIMEZONE)>=0?>

Maybe you are looking for