Getting the difference between 2 dates

Hi,
I am creating a Date object (using today;s day, month and year. hours and minutes come from a config file) and getting the difference between this date and the current date and time.
My code is as follows:
I am passing 07:30 into the method as the parameter aSstart_time.
Calendar newCalendar = Calendar.getInstance(Locale.UK);
    SimpleDateFormat dtformat = new SimpleDateFormat("dd-MM-yy HH:mm");
    int lIYear = newCalendar.get(newCalendar.YEAR);
    int lIMonth = newCalendar.get(newCalendar.MONTH);
    int lIDay = newCalendar.get(newCalendar.DAY_OF_MONTH);
    String lSstartHrs = aSstart_time.substring(0,aSstart_time.indexOf(":"));
    //System.out.println(">>>>>>>>> THE HOURS IS: " + lSstartHrs);
    String lSstartMins = aSstart_time.substring(aSstart_time.indexOf(":")+1,aSstart_time.length());
    //System.out.println(">>>>>>>>> THE MINS IS: " + lSstartMins);
    java.util.Date ldStartTime = new java.util.Date(lIYear,lIMonth,lIDay, Integer.parseInt(lSstartHrs),Integer.parseInt(lSstartMins));
    System.out.println("Year: " + lIYear);
    System.out.println("Month: " + lIMonth);
    System.out.println("Day: " + lIDay);
    System.out.println("Hour: " + Integer.parseInt(lSstartHrs));
    System.out.println("Min: " + Integer.parseInt(lSstartMins));
    System.out.println("The number of milliseconds for current time is: " + newCalendar.getTime().getTime());
    System.out.println("The number of milliseconds for 07:30 is: " + ldStartTime.getTime());
    System.out.println("calendar time: " + dtformat.format(newCalendar.getTime()).toString());
    System.out.println("created time: " + dtformat.format(ldStartTime).toString());
    if(newCalendar.getTime().getTime() < ldStartTime.getTime()){
      System.out.println("The current time is less than the config time (07:30)");
    else{
      System.out.println("The time is greater than 07:30");
    }When I run this program at 10:06am I get the following output:
Year: 2006
Month: 1
Day: 15
Hour: 7
Min: 30
The number of milliseconds for current time is: 1139997962321
The number of milliseconds for 07:30 is: 61098132600000
calendar time: 15-02-06 10:06
created time: 15-02-06 07:30
The current time is less than the config time (07:30)
The Date.gettime() method should measure the number of milliseconds after 01-01-1970 so the number of milliseconds for the current time (10:06am) should be greater than the number of milliseconds for 07:30. A you can see in the above output this is not the case.
Anybody have any idea why this is happening. Am I using the .gettime() method for the correct purpose.
Any ideas or suggestions would be greatly appreciated.
Thanks

It is beacause Calendar use fully defined year as parameter, so Calendar.set(year + 1900, month, date, hrs, min) is (almost) equivalent to new Date(year, month, date, hrs, min)Example:    int year = 85; // old way of specifying a year in a Date
    int month = 3;
    int date = 12;
    int hrs = 12;
    int min = 0;
    Calendar cal = Calendar.getInstance();
    cal.set(year + 1900, month, date, hrs, min);
    Date d = new Date(year, month, date, hrs, min);
    System.out.println(d);
    System.out.println(cal.getTime());You will obtain the same date (except seconds and miliseconds in this case, as they probably won't be zero with Calendar.getInstance(); )

Similar Messages

  • How to Get the difference between date

    Hi
    I try this query to find the difference between 2 date given in the below query.
    But the query can't be execute..
    Please try this query and give the correct one...
    select to_date(to_char(LAST_DAY('2005/03/15')+1,'yyyy/mm/dd'),'yyyy/mm/dd') - to_date('2003/06/15','yyyy/mm/dd') No_days from dual
    Thanks

    try this
    SELECT last_day(to_date('2005/03/15', 'yyyy/mm/dd') + 1) -
    to_date('2003/06/15', 'yyyy/mm/dd') no_days
    FROM dual
    LAST_DAY return a date not a varchar

  • How to get the difference between these two dates

    Hello Friends,
    I need to get the difference between these two fields which store dates but with varchar2 data types
    SELECT pac.segment1, pac.segment2 emp_no, pac.segment3 NAME,
    pac.segment4 POSITION, pac.segment5 start_date, pac.segment6,
    pac.segment7
    FROM per_analysis_criteria pac, fnd_id_flex_structures_vl ffs
    WHERE ffs.id_flex_structure_code = 'Employee Rejoin'
    AND ffs.id_flex_num = pac.id_flex_num
    AND TO_CHAR (TO_DATE (pac.segment7, 'YYYY/MM/DD HH24:MI:SS'))
    - TO_CHAR (TO_DATE (pac.segment6, 'YYYY/MM/DD HH24:MI:SS')) > 1;
    my query is something like this...
    am trying to find the difference between the last two columns but with not much luck..
    can some one suggest me a solution please

    SELECT pac.segment1, pac.segment2 person_id, pac.segment3 NAME,
    papf.employee_number, paaf.supervisor_id, pac.segment4 POSITION,
    pac.segment5 start_date, pac.segment6, pac.segment7,
    papf2.email_address,
    ( TO_DATE (TO_CHAR (pac.segment7), 'DD-MON-YYYY HH:MI:SS AM')
    - TO_DATE (pac.segment6, 'DD-MON-YYYY HH:MI:SS AM')
    + 1
    ) difference,
    POST.email_address
    FROM per_analysis_criteria pac,
    apps.fnd_id_flex_structures_vl ffs,
    per_all_people_f papf,
    per_all_assignments_f paaf,
    per_all_people_f papf2,
    (SELECT email_address, person_id
    FROM per_all_people_f
    WHERE person_id IN (
    SELECT person_id
    FROM per_all_assignments_f
    WHERE position_id IN (SELECT position_id
    FROM per_positions
    WHERE NAME LIKE 'HR Manager.704.')
    AND TRUNC (SYSDATE) BETWEEN effective_start_date
    AND effective_end_date)
    AND TRUNC (SYSDATE) BETWEEN effective_start_date AND effective_end_date
    AND business_group_id = fnd_profile.VALUE ('PER_BUSINESS_GROUP_ID')) POST
    WHERE ffs.id_flex_structure_code = 'Employee Rejoin'
    AND TO_CHAR (papf.person_id) = pac.segment2
    AND ffs.id_flex_num = pac.id_flex_num
    AND TRUNC (SYSDATE) BETWEEN papf.effective_start_date
    AND papf.effective_end_date
    AND papf.current_employee_flag = 'Y'
    AND papf.person_id = paaf.person_id
    AND TRUNC (SYSDATE) BETWEEN paaf.effective_start_date
    AND paaf.effective_end_date
    AND papf.person_id = paaf.person_id
    AND papf2.person_id = paaf.supervisor_id
    AND paaf.primary_flag = 'Y'
    AND TRUNC (SYSDATE) BETWEEN papf2.effective_start_date
    AND papf2.effective_end_date
    AND papf2.current_employee_flag = 'Y'
    and ( TO_DATE(to_char(pac.segment7), 'DD-MON-YYYY HH:MI:SS AM')-TO_DATE (pac.segment6, 'DD-MON-YYYY HH:MI:SS AM')+1) >1
    last line is giving me the error pls suggest a solution

  • Java code to get the difference between two dates in days

    Hi ppl,
    I need to write a user defined function to get the difference between two date nodes, in days.Please help me out
    regards,
    Prashanth

    Hi,
    have a look at those two:
    (How do I calculate the difference between two dates?)
    http://joda-time.sourceforge.net/faq.html
    Calculating the Difference Between Two Datetime Stamps
    http://www.xmission.com/~goodhill/dates/deltaDates.html
    Get difference in days
    http://javaalmanac.com/egs/java.util/CompDates.html
    Regards,
    michal

  • Function module to get the difference of dates ..

    Hi ,
    Can somebody pls help me with the function module to get the difference between two dates?
    I need to find the difference value and delete records if >1.
    Thanks in advance.
    Regds,
    Leeza.

    Leeza,
       When I tested the FM in my Program, it is <b>working</b>!!!!!
       Note that the Two Input Dates are to be in the format of <b>DATS</b> type (Eg: <b>vimimv-dmibeg</b>).
      U can want the Day which u have specified in the parameter I_DATUM_BIS (eg: 20050101) to be included for
    the calculation , then put X in the parameter I_KZ_INCL_BIS.
    Sample Code :
    report zkam01.
    data:           
    <b>sav_nlaufz like rf60v-nlaufz, 
    date1 type vimimv-dmibeg,
    date2 type vimimv-dmiend.</b>
    date1 = '20050101'.
    date2 = '20051001'.
    call function 'MONTHS_BETWEEN_TWO_DATES'
         exporting
             i_datum_von   = date1
             i_datum_bis   = date2
             i_kz_incl_bis = 'X'
         importing
             e_monate      = sav_nlaufz.
    write:
    date1,
    / date2,
    / sav_nlaufz.
    Please allot points if the problem is solved.
    Thanks
    Kam
    Message was edited by: Kam

  • Query to get the difference between 2 totals from 2 different queries

    I wanted to know if it is possible to get the difference between 2 totals from 2 different queries. I would explain with an example:
    1st query  - Select sum(homepass) from table 1
    2nd query – select sum(homepass) from table2
    Is it possible to display the difference like-
    Select sum(homepass) from table 1 - sum(homepass) from table2
    I know the above query would gives syntax error but is there a better way or a trick to get the above task accomplished from a single query.
    I hope, my question is clear.
    Please revert with the reply to my query.
    Regards

    tomernitin wrote:
    Try this one also:
    WITH adtn1
    AS
    SELECT 110 val1 FROM dual UNION ALL
    SELECT 100 FROM dual UNION ALL
    SELECT 90  FROM dual UNION ALL
    SELECT 10 FROM dual
    adtn2
    AS
    SELECT 10 val2 FROM dual UNION ALL
    SELECT 20 FROM dual UNION ALL
    SELECT 30  FROM dual UNION ALL
    SELECT 100 FROM dual
    SELECT(Sum(a1.val1)-Sum(a2.val2)) Diff FROM adtn1 a1,adtn2 a2;
    let me know if you still have any doubt.
    Um.... I don't think so. Not with the cartesian join between a1 and 2.

  • How to get the difference between two columns in a column group

    Hi All,
    My first time here and really new to programming. I would like to get the difference between 2 columns that are inside 
    a column group.
    Here is my sample table below: The Column Group is PeriodNumber and can only choose 2. like 1 and 2.. I would like to have a third row which will simply calculate the difference between the amounts in PeriodNumber 1 and 2.
                                PeriodNumber          
    Account                    1                            2     
    1) Cash                10,000                15,000
    2) Receivables      12,000                11,500
    3) Equipment          5,000                  5,500
    Total Assets          27,000                32,000

    Hi yabgestopa,
    From your description, you want to get the difference between two columns in a column group. After testing it in my environment, we can use custom code to achieve your requirement. For more details, you can refer to the following steps:
    Copy the custom code below and paste it to your report. (Right-click report>Report Properties>Code)
    Dim Shared Num1 As Integer
    Dim shared Num2 As Integer
    Public Function GetAmount(Amount as Integer, Type as String)
    If Type = "1" Then
    Num1=Amount
    Else
    Num2=Amount
    End If
    Return Amount
    End Function
    Public Function GetDif()
    Return Num1-Num2
    End function
    Right-click the second column to insert a third column with Outside Group-Right.
    Then use the expressions below in the matrix.
    =Code.GetAmount(Fields!Amount.Value,Fields!PeriodNumber.Value)
    =code.GetAmount(Sum(Fields!Amount.Value),Fields!PeriodNumber.Value)
    =Code.GetDif()
    The report looks like below.
    If you have any questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Do we have a way to get the differences between xtext model before and after partial parse?

    Do we have a way to get the differences between xtext model before and after partial parse?
    As an example i have file contains 4 lines, xtext parsed this file and generated its model, then i made small modification in line number 3, so xtext partially parsed the file and generated another model.
    The question is could we get the nodes that has been deleted from the model?
    could we get the new nodes added to the model?
    could we get the differences between the two models?

    Workflow {
    bean = StandaloneSetup {
    scanClassPath = true
    platformUri = "${runtimeProject}/.."
    // The following two lines can be removed, if Xbase is not used.
    registerGeneratedEPackage = "org.eclipse.xtext.xbase.XbasePackage"
    registerGenModelFile = "platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel"
    component = ParseXextModel{
    //Load the xtext model and keep the reference of the inmem model
    component = DirectoryCleaner {
    directory = "${runtimeProject}/src-gen"
    component = DirectoryCleaner {
    directory = "${runtimeProject}/model/generated"
    component = DirectoryCleaner {
    directory = "${runtimeProject}.ui/src-gen"
    component = DirectoryCleaner {
    directory = "${runtimeProject}.tests/src-gen"
    component = Generator {
    pathRtProject = runtimeProject
    pathUiProject = "${runtimeProject}.ui"
    pathTestProject = "${runtimeProject}.tests"
    projectNameRt = projectName
    projectNameUi = "${projectName}.ui"
    encoding = encoding
    language = auto-inject {
    uri = grammarURI
    // Java API to access grammar elements (required by several other fragments)
    fragment = grammarAccess.GrammarAccessFragment auto-inject {}
    // provides a compare view
    fragment = compare.CompareFragment auto-inject {}
    component = ParseXextModel{
    //Load the xtext model again and keep the reference of the inmem model
    component = CompareModel {
    //Implement this using EMF Comapre to see the differnces between 2 models
    }

  • Trying to Get the "Difference" Between Two Tracks

    What I am trying to accomplish is this: I have an audio track of a voiceover with a music bed beneath it. I also have the bed music by itsself, without the voiceover. I want only the voice portion. Is there a way that I can "cancel out" the music portion or get the difference between the two tracks (just the voice portion)? It seems that there should be some means of doing this, but for the life of me I cannot figure out how to do it!
    Any advice?

    If it's exactly the same music track, then as long as you line it up sample-accurate and the levels co-incide, you can do a simple subtractive process. You need both files available, trimmed to length. Open them both in Edit View, and copy one of them to the clipboard. Open the other, and select Mix-paste, and use the 'invert' option. That will effectively subtract one from the other, with the difference being your vocal.
    Have to tell you though that the chances of getting this spot on are amazingly low... any errors at all leave you with bleed-through, about which you can do nothing.

  • How to get the difference between two HashMaps

    i have two HashMaps
    HashMap first = new HashMap<Integer,Object>();
    HashMap second = new HashMap<Integer,Object>();
    How to get the difference between one and two and put the result in the third
    HashMap third = new HashMap<Integer,Object>();

    My bad, difference of course means removeAll():Map<Integer,Object> first = new HashMap<Integer,Object>();
    Map<Integer,Object> second = new HashMap<Integer,Object>();
    Map<Integer,Object> third = new HashMap<Integer, Object>(first);
    third.keySet().removeAll(second.keySet());No loops needed.

  • What is the difference between data base objects and runtime objects

    What is the difference between data base objects and runtime objects

    Hi raja,
    data base objects means u can have the presence of these objects in the database.So the tables,searchhelps,structures,lockobjects comes under these ones.
    Runtime objects are created and destroyed after the program ends, any changes we make to them are temporary only.
    regards,
    nagaraj
    Message was edited by: nagaraj kumar nishtala

  • What is the difference  between  data file  & control file

    what is the difference  between  data file  & control file

    Dear Deba s
    Control file
    Every Oracle Database has a control file, which is a small binary file that records the physical structure of the database. The control file includes:
    The database name
    Names and locations of associated datafiles and redo log files
    The timestamp of the database creation
    The current log sequence number
    Checkpoint information
    For more info look into these
    [Control File Basic|http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14231/control.htm#i1006143]
    Data File
    You manage Data File in your Oracle database as part of Space Management. You can extend, create, drop, and alter tablespaces.
    You especially need to avoid tablespace overflow, which is when a tablespace runs out of freespace in the allocated file or files. This happens when an object requires a new extent but there is either no freespace or insufficient freespace in the tablespace
    For more info look into these links
    [Data files |http://help.sap.com/saphelp_nw04/helpdata/en/98/5dd5890f32274aa884e45e736752a2/frameset.htm]
    http://help.sap.com/saphelp_nw04/helpdata/en/98/5dd5890f32274aa884e45e736752a2/frameset.htm
    Hope it helps you,Revert me back if you have any queries
    Assign points if helpful
    Regards
    Bala

  • How to get the difference between two date

    Hello,
    I want to know how to write a code the tell me the difference between two date, I am using
    oracle.jbo.domain.Date
    i have a rent date and return date so my code is
    Date rent=(Date)nr.getAttrbute("RentDate"),ret=(Date)nr.getAttrbute("ReturnDate");
    is there a way to know the difference in days between those two dates ?
    Thanks

    hi,
    try this.....
    DateFormat formatter = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy");
    Date date = (Date)formatter.parse(dateStr); //// dateStr <- from date value (that is string value)
    Date dateto = (Date)formatter.parse(datetostr); //// datetostr <- to date value (to date getting from as a string)
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    Calendar calto = Calendar.getInstance();
    calto.setTime(dateto);
    fromDate = cal.get(Calendar.DATE) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.YEAR);
    toDate = calto.get(Calendar.DATE) + "/" + (calto.get(Calendar.MONTH) + 1) + "/" + calto.get(Calendar.YEAR);
    // System.out.println("from Date : " + fromDate);
    if ((fromDate != null && toDate != null) && (date.compareTo(dateto) > -1) ) {                  
    fc.addMessage("VacationQueryComponent", new FacesMessage(FacesMessage.SEVERITY_ERROR, "From Date cannot be lower than To Date", "From Date cannot be lower than To Date"));
    fc.renderResponse();
    thks.

  • How to get the difference between two dates???

    HI I have two dates and I want to test if there is an hour between them.
    Is there a way to compare two dates like mySQL can with dateDiff(date1,date2);
    Thanks alot.
    Graham

    This link is now out of date as they have revamped the structure. Yep. Here it is again: http://forum.java.sun.com/thread.jsp?forum=31&thread=502686
    I've also noticed that my comment regarding daylight saving was misleading. The demonstrated method for calculating difference between Dates is reliable. However, one needs to be careful when interpreting Dates in a daylight saving timezone.

  • What's the difference between data source and source system in BI

    hello
    what's the basic and exact difference in BW 3.0 and BI 7.0. i am very urgent indeed. can anyone help me - how the things should be done here. it's preety confusing.
    Can anybody give me the step by step analysis.
    Thanks in advance
    C.S.Ramesh

    Hi,
    Chk the foll links...
    See this very nice presentation prepared by Dr Berg on new features of BI 7.0 (these are the differences between BI 7.0 and BW 3.5):
    http://csc-studentweb.lrc.edu/swp/Berg/Articles/NW2004s_what_is_new.ppt
    Check the release notes:
    http://help.sap.com/saphelp_nw2004s/helpdata/en/a4/1be541f321c717e10000000a155106/content.htm
    This presentation:
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/910aa7a7-0b01-0010-97a5-f28be23697d3
    Web Blog:
    /people/michael.eacrett/blog/2006/06/07/whats-new-in-sap-netweaver-702004s--an-introduction-to-the-functionality-deltas-and-major-changes
    You can also refer below posts:
    Re: BW 7.0 Release
    /message/1383908#1383908 [original link is broken]
    Upgrade from BW 3.5 to BW 7.0 (BI 7.0)
    Some features of BI 7 are
    1. In Infosets now you can include Infocubes as well.
    2. The Remodeling transaction helps you add new key figure and characteristics and handles historical data as well without much hassle. This is only for info cube.
    3. The BI accelerator (for now only for infocubes) helps in reducing query run time by almost a factor of 10 - 100. This BI accl is a separate box and would cost more. Vendors for these would be HP or IBM.
    4. The monitoring has been imprvoed with a new portal based cockpit. Which means you would need to have an EP guy in ur project for implementing the portal !
    5. Search functionality hass improved!! You can search any object. Not like 3.5
    6. Transformations are in and routines are passe! Yess, you can always revert to the old transactions too.
    this is a good PDF on Upgrade from BW 3.5 to BW 7.0
    latest on upgrade tp BI7.0
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/2e8e5288-0b01-0010-2ea8-bcd4df5084a7
    http://help.sap.com/bp_epv170/EP_US/Documentation/How-to/Planning/Master_Guide_NW2004s.pdf
    You can seek more information on BI 7.0 in the SAP NetWeaver2004s Ramp-Up.
    /community [original link is broken]
    Re: BW 7.0 Release
    Re: BW 7.0 Release
    Re: BW 7.0
    take a look presentation
    overview
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5ee3725b-0401-0010-e381-ac323362ce91
    detail
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5c46376d-0601-0010-83bf-c4f5f140e3d6
    https://www.sdn.sap.com/irj/sdn/developerareas/bi?rid=/webcontent/uuid/e78a5148-0701-0010-7da9-a6c721c6112e [original link is broken]
    may useful .....
    https://www.sdn.sap.com/irj/sdn/developerareas/bi
    http://help.sap.com/saphelp_nw04s/helpdata/en/e3/e60138fede083de10000009b38f8cf/frameset.htm
    Hope this helps.

Maybe you are looking for

  • Having trouble saving tiff files to server

    Hi all, I'm having trouble saving tiff files to our server (a mac pro running OSX 10.5.7 client not server). I get the error message 'could not save "filename" because write access was not granted. The disk in question is set to ignore permissions an

  • Javascript suddenly stopped functioning in Firefox?

    I'm working with a site that stopped working in Firefox randomly. This piece of code is populating into the html each time I try to update, and I'm trying to understand it. I haven't made any changes to the javascript used in the site but whatever th

  • New macmini - keyboard fails to pair

    I just unpacked a new macmini. My old mouse will pair with it (I use a trackpad on the i7 now) but the new wireless keyboard will not pair with the macmini. I tried powering off the i7 and removing batteries from the othey keyboard and trackpad but t

  • Character Strings in Sap Script

    Hi, how to create character strings in Sap Script? thanks, fractal

  • Second 4th gen nano that has become completely unresponsive

    This is my second 4th generation iPod nano. The first stopped working properly on the second day. It wouldn't hold a charge, it wouldn't turn on, and iTunes would not recognize it. Now it's the same thing. I returned it and got another one. This one