How compare 2 dates

hello
i need compare 2 dates and fird difference between them
for example 30 september and 1 october
difference = 1 day
how i can make it ?
compareTo(Date) make it something else
here is code
import java.util.*;
import java.text.*;
public class DateWork2 {
public static void main(String[] args){
int i;
GregorianCalendar today=new GregorianCalendar();
GregorianCalendar oldday=new GregorianCalendar (2001,Calendar.AUGUST,16);
Date d1 = today.getTime();
Date d2 = oldday.getTime();
DateFormat df_today=DateFormat.getDateInstance(DateFormat.SHORT);
DateFormat df_oldday=DateFormat.getDateInstance(DateFormat.SHORT);
String s1=df_today.format(d1);
String s2=df_oldday.format(d2);
System.out.println(s1);
System.out.println(s2);
i=d1.compareTo(d2);
System.out.println(i);
thanks at advance

If you call getTime on a Date object (yes, this is totally different from Calendar's getTime), you'll get the number of milliseconds since 1970-01-01 00:00:00 UTC. Therefore,
d1.getTime() - d2.getTime()is the time difference in milliseconds. To convert it to days, simply divide by 86 400 000.

Similar Messages

  • How compare data from 2 different ODS and then load data to Cube

    Hello, everybody,
    I  have 2 ODS ZINFO_1 and  ZINFO_2. These ODS contain data:
    ZINFO_1
    document number; item number; amount
    10004;1;200
    10004;3;330
    10004;4;650
    10005;1;110
    ZINFO_2
    document number; item number; amount
    10004;1;700
    10004;4;430
    After comparison ODS ZINFO_1 with ZINFO_2, into InfoCube ZICINFO_3 I have get data from ODS ZINFO_1 that document number and item number is not equal to ZINFO_2 ODS’s document number and item number.
    Data in InfoCube ZICINFO_3 should be:
    ZICINFO_3
    document number; item number; amount
    10004;3;330
    10005;1;110
    Could you give me suggestions how do this?
    Thanks in advance.
    Best Regards,
    Arunas Stonys

    Most of the time you write a routine in the update rule and you want to read a table or ODS to look up for that particular field you are intersted in, if you are doing reading the table or DSO in the update rule, it will execute for each and every record, but you do reading the table in the start routine which will get executed for each data package and in your update rule, you read the internal table to put your logic.     
    The Start rouline can be as follows
    Please do modify this routline for ur requirement
    Another situation where I am loading DATA from DSO 1 to DSO 2 and looking for Records from DSO3 and DSO4.
    DSO1---->DSO2(looking up data from DSO3 and DSO4 to update to DSO2).
    NOw in the start routine I define 2 internal tables for DSO3 and DSO4 having sturctures like DSO3 and DSO4(with only useful fields and key fields,becoz u may not need all the fields from dSO3 and DSO4 afterall)
    Now I am loading data in those interanal tables by using SELECT Query in START routine.
    Now In various transformatino rule for populating different target fields I am reading those internal tables(itab_dso3 and itab_dso4) putting the read and where condition like
    Code for field Z(of DSO2)
    Read fieldX fieldY fields Z from itab_dso3 into wa_dso3 with key fieldsX=source_fields-fieldsx fieldY=source_fields-fieldsy.
    if sy-subrc eq 0.
    result = wa_dso3-fieldz
    endif.
    (here i am reading the itab loaded in start routine and reading it with the help of two source fields(dso1 fields fieldX and fieldY ) and comparing them with DSO3 .If there is a match then I am udpating fieldz of DSO2 with fieldZ from DSO3.)
    Please do assign points if it is needful.
    Thanks in advance.
    Best WIshes,
    VVenkat.

  • 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

  • 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 Date/time string

    I read from datalog file including Date/time string ,and want to query the special Date/time string span ,how to compare the data/time string ?

    Hello Joshua,
    To compare date/time you have to extract the different components (day, month, year, hour, minute, second) anyway. Why not "convert to seconds"? I think it's easier to compare one number (where you also can do other math, like calc the difference and so on) than to compare seven (?) parameters with some exceptions... If the dates are read from excel (there was a similar thread some days ago), why not convert to seconds in excel (just a format change)?
    Best regards,
    GerdW
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • How to compare data from 2 different time periods

    Hi folks,
    I have a question on approach to a problem. I want to be able to compare data from a common db, but for 2 different time periods. For example I want to see the number of occurences of an instance in my data for today and compare it against occurences a week ago today. What's the best approach for this kind of problem? Is this done with 2 separate queries from 2 sub reports and then compared some how? Any comments on this approach or an other are appreciated.
    TIA bvd

    Follow these steps:
    1) Bring your first time period in your main report.  This will be your first query.
    2) Bring your second time period in a subreport.  This will be your second query.
    3) Bring the values from your subreport into your main report using shared variables.
    4) Lastly, compare the results using formulas in your main report.
    I hope this information proves useful.
    Regards,
    Zack H.

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

  • How to compare date between 2 file?

    hi there...
    is there any possibility to compare date between 2 file and the file that is latest to open?
    thank you

    i need help urgently..... i type tis code
    <%
    String file = ("C:/");
    File f = new File(file);
    String [] fileNames = f.list();
    File [] fileObjects= f.listFiles();
    %>
    <UL>
    <%
    for (int i = 0; i < fileObjects.length; i++) {
    if(fileObjects.lastModified()){
    %>
    <LI>
    <a href="<%= fileNames[i %">"><%= fileNames[i] %></A>
    <%
    %>
    my purpose is to list out all the file in the folder but not to the user just for the system to check all the files than when i click a link it will open the latest file
    Message was edited by:
    n_dilah</a>

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

  • Why do I have to guess how much data I might use in a month when I select a plan?

    When I sign up for water service, I don't guess that I might use 1,000 gallons a month, and then pay three times the going rate for water if I take a few extra showers. I get charged for how much water I use that month.
    When I sign up for electricity service, I don't guess that I might use some set number of kilowatt hours, and then pay three times the going rate if we have a heat wave and I run my air conditioner for a few extra hours.
    Why do I have to guess how much data I might use, and then spend three times the going rate if I stay up watching youtube videos for a few extra nights?
    It is stressful to have to constantly monitor usage, and figure out ratios of how much I've used compared to how much time is left in the billing cycle to see if I need to curb my usage. It is not a good customer experience. I would prefer that data be charged a flat rate based on actual usage, perhaps with an option to throttle speeds at certain levels to prevent cases where a minor lapse in judgment could ruin my monthly budget, like forgetting to check data usage religiously on a device meant to simplify my life.
    Thank you for your consideration.

    Simple answer is Verizon is offering a block of data for usage.
    Where I live the water bill states my wife and I are being charged for 30,000 gallons per quarter/half and the price is say $60 however we never use any where near that amount. I send the meter reading in and it shows the amount we use. But the hamlet we are in has a set amount of gallons. Not fair but we live with it.
    For your data outside of the unlimited which is not available any more to new customers you may be a light user and never go over the 2GB for $30 dollars a month. If you do you will pay through the nose for data. If you pay for more data say 4GB and I don't have the price for it so lets say its $70 then you don't have to watch as much for overage fees. But you are paying for the data in advance so as not go over and get hit with whopping fees.
    It is just the way it is.

Maybe you are looking for

  • Env:Server

    Dear all, I run a interface on bpel, this interface is a query data form database.When I select 2009-07-16 13:34:00--2009-07-16 14:34:00 it return error as follows: <Faulthttp://schemas.xmlsoap.org/soap/envelope/> <faultcode>env:Server</faultcode> <f

  • Select Governance Model

    Hello, I am newly joined in a company where my task is to select governance model for all data elements implemented within the project. The project is to consolidate all customer, vendor and material master from 4 R/3 systems in to 1 new ECC Systems.

  • How TO Update Inbound IDOC....

    Hi experts, I have a requirement to update inbound ORDERS IDOC. On receive of IDOC we need to check value for E1EDP01-PSTYV and change it . Can we change values back to the IDOC? Regards, Akshay Jamgaonkar.

  • Adding content to a textframe

    Hi all, I want to add some content to a textframe which already has some text in it. If i use the following code tframe.content += "appended text" then the text is appended to the textframe but all the text that was previously present in the the text

  • HT4993 where/how can i unlock a sprint iphone 5?

    where/how can i unlock a sprint iphone 5?