Code to genereate difference between succcessive dates in a table

First create and Insert statements;
create table schedule(iloan_code number , schedule_date date);
insert into schedule values(1001, to_date('01-jun-2012'));
insert into schedule values(1001, to_date('01-jul-2012'));
insert into schedule values(1001, to_date('01-aug-2012'));
insert into schedule values(1001, to_date('01-sep-2012'));
insert into schedule values(1001, to_date('01-oct-2012'));
commit;THe output of the SCHEDULE table shall be now like this:
ILOAN_CODE     SCHEDULE_DATE
1001              01-JUN-12
1001              01-JUL-12
1001              01-AUG-12
1001              01-SEP-12
1001              01-OCT-12we want an extra column by name DAYS along with the existing columns which would be the difference between the dates.
First row should be the difference between sysdate and the date 01-jun-2012 and the successive rows must be the difference between successive schedule dates
For instance in the second row the DAYS column must represent the difference between 01-jul-2012 and 01-jun-2012 and so on for the next rows too.
We need to get the output through a SELECT statement
The output of the SCHEDULE table must be somthing like this.
iloan_code      schedule_date     days     Logic which we need
1001     1-Jun-12     22     sysdate-1st June 2012
1001     1-Jul-12     30     difference between 1st July 2012 and 1st June 2012
1001     1-Aug-12     31     difference between 1st aug 2012  and 1st July 2012
1001     1-Sep-12     31     difference between 1st sep  2012 and 1st aug  2012
1001     1-Oct-12     30     difference between 1st oct 2012 and 1st sep 2012Please advise;

Hi,
sri wrote:
... Could you please let me know the formatting procedure used for the output . I have used (code) (code) (you can consider ( for { ) concept but could not display the
expected results properly.I'm not sure what you're saying.
To preserve spacing, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text.
Alternatively, you can use these 6 characters
[code]
(case insensitive, inside square brackets) at the beginning of a formatted section, and these 7 characters
[/code]
(with a forward /) at the end of the formatted section.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • 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

  • How to build a difference between to dates

    Hi @All,
    Hope you can help me :) ..
    I'd like to build the "difference" between two dates (e.g. date of the invoice and date of the payment receipt). As the result I expect an Integer.
    I tried several functions and operations, but still get the error code: [nQSError: 22023] An arithmetic operation is being carried out on a non-numeric type.
    I also tried to cast the date format into an Integer or double, but I still get an error ...
    Here is my code:
    CASE WHEN "2_Forderungsstruktur_Fälligkeiten".DIM_DATUM_FAELLIGKEIT.DDAT_DATUM_DE < 0
    THEN NULL
    ELSE
    "2_Forderungsstruktur_Fälligkeiten".DIM_DATUM.DDAT_DATUM_DE - "2_Forderungsstruktur_Fälligkeiten".DIM_DATUM_FAELLIGKEIT.DDAT_DATUM_DE
    END
    Hope you guys have some good ideas to solve these problem :)
    best regards
    Matt

    hi,
    TIMESTAMPDIFF(SQL_TSI_MONTH,"Dim - Time"."Date",CURRENT_DATE)
    "Dim - Time"."Date"--->Column1
    Current_date--->Column2
    thanks,
    saichand

  • Difference between two date in bex query

    Hi all,
    I need to do a difference between two date using formula variable processing type customer exit beaucause I must use factory calendar in the formula.
    How can I do it?
    Can you give me an example of the routine?
    Thanks a lot
    Gianmarco

    Hi,
    You can still use the same code to copy it and customize as per your need. All you need to do is to subract the dates using the class: CL_ABAP_TSTMP after converting to timestamp and resulting seconds you convert back to days....Please get help from the developers to do this...
    Also, ensure that you write back this difference value to your variable so you get it on the reports for your calculations...
    Cheers,
    Emmanuel.

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

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

  • Difference between Two Date Should come into Text Item

    Dear All,
    i want to get difference between two date into text Item :P36_C in On Change java script.
    i have two Date Item :P36_A and :P36_B .i have extract these date value from table then difference comes into Text Field :P36_C.
    Now i want if i change Date into Item :P36_A or Item :P36_B then Defference between two date Should Come into Item :P36_C .
    So i have use Java Script Code to do this
    <script>
      function diffdat(){
        function getVal(item){
       if($x(item).value != "")
         return parseFloat($x(item).value);
       else
         return 0;
        $x('P36_C').value =
    getval((TO_DATE('P36_B', 'DD-MON-YYYY'))-
    getval(TO_DATE('P36_A', 'DD-MON-YYYY')))+1;
    </script>
    i have put this into Item HTML Form Element Attributes 
    onChange="javascript:diffdat();"it's not woring .
    How to work that Code with dates.
    Thanks

    You can always create your own difference function based on your own criteria. You can modify this to suit your needs.
    CREATE OR REPLACE FUNCTION CALC_OFFICE_DAYS(date1 DATE, date2 DATE)
    RETURN NUMBER
    IS
    v_begin_date DATE := date1;
    v_end_date DATE := date2;
    v_office_start_time VARCHAR2(10) := '09:30 AM';
    v_office_end_time VARCHAR2(10) := '06:30 PM';
    v_comp_begin_time DATE;
    v_comp_end_time DATE;
    v_days PLS_INTEGER := 0;
    v_hrs NUMBER := 0;
    v_ttltm NUMBER;
    BEGIN
    select trunc(v_end_date) - trunc(v_begin_date)
    into v_days
    from dual;
    select to_date(to_char(sysdate,'DD-MM-YYYY')||' '||to_char(v_begin_date,'HH24:MI'),'DD-MM-YYYY HH24:MI')
    into v_comp_begin_time
    from dual;
    select to_date(to_char(sysdate,'DD-MM-YYYY')||' '||to_char(v_end_date,'HH24:MI'),'DD-MM-YYYY HH24:MI')
    into v_comp_end_time
    from dual;
    select (v_comp_end_time - v_comp_begin_time)/24 into v_hrs from dual;
    IF v_hrs > 4 then
    v_ttltm := v_days + .5;
    ELSE
    v_ttltm := v_days;
    END IF;
    return v_ttltm;
    END;
    As has been noted, this question is best posted on the PL/SQL forum.

  • Can any one tell me difference between 2 dates in days

    hi guys,
    can any one tell me the difference between 2 dates in days
    for eg: input  20.12.2006 and 06.11.2006 will be 34.
    thanks in advance for you answers
    Regards,
    Anil kumar P

    Hi Anil,
    Check this code for u r requirement
    REPORT ZDATEDIFF.
    DATA: EDAYS LIKE VTBBEWE-ATAGE,
    EMONTHS LIKE VTBBEWE-ATAGE,
    EYEARS LIKE VTBBEWE-ATAGE.
    PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,
    TODATE LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.
    call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
    exporting
    i_date_from = FROMDATE
    i_date_to = TODATE
    I_FLG_SEPARATE = ' '
    IMPORTING
    E_DAYS = EDAYS
    E_MONTHS = EMONTHS
    E_YEARS = EYEARS.
    WRITE:/ 'Difference in Days ', EDAYS.
    WRITE:/ 'Difference in Months ', EMONTHS.
    WRITE:/ 'Difference in Years ', EYEARS.
    INITIALIZATION.
    FROMDATE = SY-DATUM - 60.

  • Calculate difference between two dates/times

    Hi all,
    Is there any function module to calculate difference between two dates/times which are in TIMESTAMPL format.
    I need to know how many millisconde(second,minutes, hours... )there is between these two times.
    Please, It is urgent
    Thank you all.
    Karim

    hi,
    try the following function
    CALL FUNCTION 'CCU_TIMESTAMP_DIFFERENCE'        
          EXPORTING                                  
               timestamp1 = timestamp1               
               timestamp2 = timestamp2               
          IMPORTING                                  
               difference = diff                     
          EXCEPTIONS                                 
               OTHERS     = 1. 
    the above function gives the difference in seconds...
    try the following  code to set the resolution to milliseconds..
    SET RUN TIME CLOCK RESOLUTION LOW
    check the thread for details:
    SET RUN TIME CLOCK RESOLUTION?
    all the best!!!
    Regards,
    Aparna

  • Calculate the difference between two dates times in infopath form 2013

    Hi,
    I have an infopath 2013 form that contains three fields:
    2 date time and the 3rd contains the difference between the two in hours
    how I can make the difference between the two so that the display will be like this:
    Date Time1           08/21/2014           22:00 
    Date Time2           08/22/2014           1:00
    Diff Field                                             3:00

    Hi,
    Please refer to the following article which matches your requirement exactly.
    Calculate the difference between two date picker controls in InfoPath using rules and formulas - no code!
    Please mark it answered, if your problem resolved.

  • [Urgent] Need help calculating difference between two dates

    I'm trying to write a code to display the current day and time, then accept two dates from the user and display the difference between the two dates. To display the current date and time, I've used the SimpleDateFormatter library but I'm having difficulty calculating the difference between two dates. Could someone please help me with this?
    Below is my code so far
    import java.util.Date;
    import java.util.Scanner;
    import java.text.SimpleDateFormat;
    public class DateFormatter {
         public void displayNow()
              Date todaysDate = new Date();
              SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
              String formattedDate = formatter.format(todaysDate);
              System.out.println("Today's date and time is: "+formattedDate);
         public void calculateDifference(Date startDate, Date endDate)
              /* This is whre i need help! */
         public static void main(String[] args)
              DateFormatter df = new DateFormatter();
              Scanner sc = new Scanner(System.in);
              df.displayNow();
              System.out.println("Please enter a date: ");
              String date1 = sc.next();
              System.out.println("Please enter another date: ");
              String date2 = sc.next();
    }The methods displayNow() and calculateDifference(Date startDate, Date endDate) are essential and cannot be skipped out.

    tarahmarie101 wrote:
    Dude. I've tried doing assignments under pressure, and it doesn't work. Here's a piece of free advice. Start earlier next time, don't put "urgent" in the title of your post b/c it just pisses people off around here--and is a sure sign of an overdue homework assignment which no one around here likes helping with, and try to ask intelligent questions--don't just say "Help me!"
    Of course, it takes some time to learn what the intelligent questions are. You have my sympathy. Try asking questions about how to do a particular task, instead of asking people to tell you what to do. It starts to get easier after a while.
    actually dude i started on this on monday.. but there were so many other stuff to do along with this.. and i did try referring up the Calendar utility but it was a bit confusing actually.. it was only after that did i come to this forum.. nor am i very good at Java.. anyhoo thanks for your sympathies :P

  • What is the difference between delivery date and actual goods issue date?

    Hi ,
    Can you please tell me the difference between Delivery date and Actual goods issue date ?
    Delivery data can be be greater than goods issue date?
    Thanks,
    Ajay

    Hi Ajay,
                  Delivery date means its the original date on which the delivery should be done.Actual goods Issue date is the date on which goods to be delivered according to the purchase order.There can be delay in the delivery so we maintain 2 objects.
    Yes delivery date can be greater than Goods Issue date.
    Hope this clears
    Regards
    Karthik

  • As to the data type of the data type of the difference between two date type of datas

    Hi,
    I have a question about the data type of the difference between two date type of datas.
    There are two date type of datas as:
    SSHIPMENTS.RECEIVEDATETIME
    SSHIPMENTS.PROMISEDATETIME
    I try to use the following SQL Script in Oracle SQL*Plus as:
    SELECT CASE
    WHEN (SSHIPMENTS.RECEIVEDATETIME - SSHIPMENTS.PROMISEDATETIME) < '000 01:00:00.000' THEN 'OnTime'
    WHEN (SSHIPMENTS.RECEIVEDATETIME - SSHIPMENTS.PROMISEDATETIME) < '000 01:30:00.000' THEN '60-89 Minutes'
    ELSE '3+ Hours'
    END
    FROM SSHIPMENTS;
    The error message of "Invalid Number" for the '000 01:30:00.000' happens.
    I don't know if the data type of the interval is wrong.
    Many Thanks,
    Cathy

    SELECT CASE
    WHEN (to_char(SSHIPMENTS.RECEIVEDATETIME,'hhmiss') - to_char(SSHIPMENTS.PROMISEDATETIME,'hh24miss')) < '010000' THEN 'OnTime'
    WHEN (to_char(SSHIPMENTS.RECEIVEDATETIME,'hhmiss') - to_char(SSHIPMENTS.PROMISEDATETIME,'hh24miss'))< '000 01:30:00.000' THEN '60-89 Minutes'
    ELSE '3+ Hours'
    END
    FROM SSHIPMENTS;
    just try it out..

  • Difference between Invoice Date, GL Date and Accounting Date Oracle AP

    Hello,
    I have a question that might help a lot of people too later.
    I tried to run these queries
    select aia.INVOICE_ID
    from AP_INVOICES_ALL aia, AP_INVOICE_DISTRIBUTIONS_ALL aida
    where aia.INVOICE_ID = aida.INVOICE_ID
    and aia.INVOICE_DATE <> aida.ACCOUNTING_DATE
    select aia.INVOICE_ID
    from AP_INVOICES_ALL aia, AP_INVOICE_DISTRIBUTIONS_ALL aida
    where aia.INVOICE_ID = aida.INVOICE_ID
    and aia.GL_DATE <> aida.ACCOUNTING_DATE
    I can see that there are lot of results for these queries, where the Invoice Date is not equal to the Accounting date and the GL_Date of an invoice is not equal to the accounting date in the distributions table.
    So, what is the difference between these dates.
    And if I had to take the Invoice Accounting document entry date, which date do i have to take for these invoices in AP
    Thanks
    Bob

    Hi
    Let me try to explain this with an example.
    Suppose I buy some stationary from a vendor and he provides me with a detailed invoice of the goods puchased.
    In this case the invoice will always have a date printed on it and this date should ideally be entered in the invoice date at AP_INVOICES_ALL level.
    Now suppose the invoice happens to be received by me in february and for some reason I could not capture the invoice in my books in february and made a provision for the liabilities and close the books.
    However in march i want to book the invoice say on 10th of march in my books and pay the vendor the amount payable.(I Have to reverse the already provided liability in march to reverse the accounting effect).
    In this case my book entry date of invoice is the accounting date i.e. 10 March.
    In case of oracle, the accounting is maintained so that the invoice header hits the liability account while the invoice distribution hits the charge account(expense account so to say). And to gain more flexibility oracle provides date in both header and distributions to provide an option of booking liability and charge on different dates..
    As per the 11i checks there is no check on any of these dates except that accounting date at header and ditribution level must be in an open AP and GL period.
    Thanks
    MAV.

  • Difference between doc date,posting date and invoice date

    hi bw guys
    can someone give a brief on the difference between doc date,posting date and invoice date.and the invidual definitions
    thank you

    Hi,
    Posting Date: Date which is used when entering the document in Financial Accounting or Controlling. The posting date can differ from both the entry date and the doc date.
    Document Date: The document date is the date on which the original document was issued. Ex: Inv date, Bill date etc.,
    Invoice Date : Usually the date when goods are shipped. Payment dates are set relative to the invoice date.
    -Vikram

Maybe you are looking for