Number of days between two objects Oracle.jbo.domain.Date

I have two objects Oracle.job.domain.Date:

Date = StartDate (Date) CurrentRow.getAttribute ("StartDt");
Date = CurrentDate (Date) this.getOADBTransaction () .getCurrentDBDate ();

I want to find the number of days between StartDate and CurrentDate.
I tried the CompareTo () function, but its does not not the desired results.
Can someone let me know how I can find the number of days between StartDate and CurrentDate above?

Concerning
Hawker

Hawker,

Use the code below

Date StartDate= (Date)CurrentRow.getAttribute("StartDate");
    Date CurrentDate = (Date)am.getOADBTransaction().getCurrentDBDate();
    java.sql.Date sdate = (java.sql.Date) StartDate.dateValue();
    java.sql.Date cdate = (java.sql.Date) CurrentDate.dateValue();
    int days = daysBetween(sdate,cdate );

  public int daysBetween(java.sql.Date d1, java.sql.Date d2){
     return (int)( (d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24));
         }

Kind regards
GYAN

Published by: Gyan on 27 March 2011 19:56

Tags: Oracle Applications

Similar Questions

  • Dynamic calculation of the number of days between two dates in a table

    Hello

    I'm working on request where I dynamically calculate the number of days between two dates in a table.

    The calculation must be dynamic, i.e., when I recover the Start_date and End_date and move to the field following (call_duration) in the same row, the difference must be calculated dynamically in this area and make sure the field read-only.

    APEX version: 5.0

    Hi BO123,

    BO123 wrote:

    Hello

    I'm working on request where I dynamically calculate the number of days between two dates in a table.

    The calculation must be dynamic, i.e., when I recover the Start_date and End_date and move to the field following (call_duration) in the same row, the difference must be calculated dynamically in this area and make sure the field read-only.

    APEX version: 5.0

    one of the way to do this by calling ajax on change of end_date.

    See the sample code given below to fetch the resulting duration and making the field read only after calculation

    Step 1: Change your page

    under CSS-> Inline, put the code below

    .row_item_disabled {
      cursor: default;
      opacity: 0.5;
      filter: alpha(opacity=50);
      pointer-events: none;
    }
    

    Step 2: Create on demand Ajax process I say CALC_DURATION

    Please check Procces Ajax, see line 6.7 How to assign a value to the variable sent by ajax call

    Declare
      p_start_date  date;
      p_end_date    date;
      p_duration number;
    Begin
      p_start_date  := to_date(apex_application.g_x01);
      p_end_date    := to_date(apex_application.g_x02);
    
       --do your calculation and assign the output to the variable p_duration
      select p_end_date - p_start_date into p_duration
        from dual;
    
      -- return calculated duration
      sys.htp.p(p_duration);
    End;
    

    Step 3: Create the javascript function

    Change your page-> the function and the declaration of the Global Variable-> put the javascript function

    You must extract the rowid in the first place, for which you want to set the time, see line 2

    assuming f06, f07 and f08 is the id of the start date, and end date columns respectively, and duration

    See no line no 8 how set the value returned by the process of ajax at the duration column

    Replace your column to the respective column identifiers in the code below

    function f_calulate_duration(pThis) {
      var row_id  = pThis.id.substr(4);
      var start_date = $('#f06_'+row_id).val();
      apex.server.process ( "CALC_DURATION", {
      x01: start_date,x02: $(pThis).val()
    }, { success: function( pData ) {
    // set duration to duration column
    $('#f08_'+row_id).val(pData);
    // disable duration column
    $("#f08_" + row_id).attr("readonly", true).addClass('row_item_disabled'); }
    });
    }
    

    Step 4: choose the end date call the javascript function

    Go to report attributes-> edit your Date column end-> column-> Attrbiutes element attributes-> put the code below

    onchange="javascript:f_calulate_duration(this);"
    


    hope this helps you,

    Kind regards

    Jitendra

  • JavaScript anomaly on the number of days between two dates

    Use ApEx 4.0, I found an anomaly in a javascript code that calculates the number of days between two dates, the current_date and the past_date. If the past and present is the or before March 10, 2013, and the current_date lies between 10 March 2013 and November 3, 2013, the number of days will be from 1 day to less than the actual number. Between November 3, 2013 and on 4 November 2013, the increments of number by 2, then the count will be accurate from this date forward.

    Here are some examples:

    March 10, 2013 = 69 days of December 31, 2012
    March 11, 2013 = 69 days of December 31, 2012
    March 12, 2013 = 70 days of December 31, 2012

    November 3, 2013 = 306 days in December 31, 2012
    November 4, 2013 = 308 days in December 31, 2012

    11 March should be 70 and 12 March should be 71. November 3 is 307 and 4 November corrects the number of fake, which began March 11.

    Change the past_date to March 10, 2013 produces the following:

    March 10, 2013 = 0 days of March 10, 2013
    March 11, 2013 = 0 days of March 10, 2013
    March 12, 2013 = 1 days of March 10, 2013

    But change the past_date to 11 March 2013, product of the correct numbers:

    March 11, 2013 = 0 days of March 11, 2013
    March 12, 2013 = 1 days of March 11, 2013
    March 13, 2013 = 2 days of March 11, 2013

    I would certainly all help to determine the cause of this anomaly. Here's the javascript code:

    var w1 = ($v ("P48_PAST_DATE"));
    W1 = (w1.toString ());
    vmon var = (w1.substr (3.3));
    vyr var = (w1.substr (7));
    var r = (vyr.length);
    If (r == 2)
    vyr. = (parseFloat (vyr) + 2000);
    vday var = (w1.substr (0.2));
    var y = (vmon.concat ("", vday, ",", vyr));
    y = Date.parse (y);

    var w2 = ($v ("P48_CURRENT_DATE"));
    var vmon2 = (w2.substr (3.3));
    var vyr2 = (w2.substr (7));
    var vday2 = (w2.substr (0.2));
    var x = (vmon2.concat ("", vday2, ",", vyr2));
    x = Date.parse (x);

    var numdays = (x - y);
    numdays = (Math.floor(numdays / 86400000));
    $s ("P48_NUMBEROFDAYS", numdays);

    Did you google for something like "javascript number of days between two dates. I think you will find the explanation to this observation:

    This method does not work correctly if there is an advanced economies jump between the two dates.

    There are examples available to calculate the difference between two dates.

  • Calculate the number of days between two dates

    Hello

    Can someone help please change my formcalc script to calculate the number of working days between two date fields.  My script currently calculates the total number of days between two dates, including the weekends which must be excluded from the total.

    If

    (HasValue (Start_Date1) & HasValue (End_Date1)) then

    $

    = Date2Num (End_Date1, "YYYY-MM-DD" "en_IE") - Date2Num (Start_Date1, "YYYY-MM-DD" "en_IE") + 1

    on the other

    ""

    endif

    Any help will be most appreciated.

    Thank you.

    Check...

    (1) you said that you put the script on the event «days1» calculate My sample imitates the variable names used in the original message, "Start_Date1" and "End_Date1". If the names of variables for the start and end dates are different, you will need to modify the script to account for these names.

    (2) the Date2Num functions in the calculation of the "totalDays" use the date format "YYYY-MM-DD". If your date habits differ from "YYYY-MM-DD" FormCalc will complain.

    Steve

  • setCreatedBy (int) cannot call setCreatedBy (oracle.jbo.domain.Number) EOImpl, setCreationDate (Calendar) cannot call setCreationDate (oracle.jbo.domain.Date) in EOImpl

    Hello world

    I get the following errors when you try to initialize a record:

    • setCreatedBy (int) cannot be called setCreatedBy (oracle.jbo.domain.Number) in EOImpl
    • setCreationDate (Calendar) cannot call setCreationDate (oracle.jbo.domain.Date) in EOImpl

    setCreatedBy (value) must be a FND_USER. USER_ID. He wanders ins the following statement: setCreatedBy(-1);

    setCreatedDate (value) must be today's date.

    setWeekDate (value) must be the Sunday after today's date.

    protected void doDML (int operation, TransactionEvent e) {}

    Begin

    Calendar date = Calendar.GetInstance ();

    If (operation == DML_INSERT) {}

    setLineId ((new_SequenceImpl_("tke_tp_cus_cd_14_lines_s",___getDBTransaction()).getSequenceNumber (()));

    setBillable ("T");

    setCreatedBy(-1);

    setCreationDate (date);

    setWeekDate (date);

    }

    End

    super.doDML (operation, e);

    }

    Please be patient... I'm a noob! Thanks in advance!

    James

    James,

    What version of Jdev do you use?

    Can you post the code that you use after all the changes?

    For the setLineId try new oracle.domain.Number(-1)

    Timo

  • Could not create the domain object type oracle.jbo.domain.Date

    Hello

    I'm getting the following exception in the user interface when I click on submit button (/ commit or any other button) for date fields. I created the default objects entity and notices for the database table. I'm poplating the data after executing the "Execute" operation on the iterator for the view.

    Cannot be created with the value ' 22/09/2009' field object type oracle.jbo.domain.Date. +

    Even if I had not made any changes to the date also fields, it's give the exception message in the user interface and do not return the form.

    Could you please help me to solve the issue.

    Thank you and best regards,

    S R Prasad

    Published by: oumar s Prasad on November 18, 2009 15:01

    Prasad,

    What is your version of JDev? And what technology do you use to model? BC4J? Can you try to change the format of the attribute in the object view? Say with the type of Simple date format and format "mm/dd/yyyy".

    Arun-

  • Conversion problem of oracle.jbo.domain.Date in java.util.Calendar and oracle.jbo.domain.Timestamp to oracle.jbo.domain.Date

    Hello world

    Work with dates has been harder than I thought! Please take a look at the code; everything compiles, but it fails because I'm not cast properly. Any help would be appreciated.

    Imports are:

    import java.sql.SQLException;

    to import java.text.ParseException;

    import impossible;

    import java.util.Calendar;

    Import oracle.jbo.domain.Date;

    Import oracle.jbo.domain.Timestamp;

    Here is the method:

    public static Date (String sDate, int day, nextDay

    SimpleDateFormat String) {}

    Date result = null;

    java.util.Date date;

    If (sDate! = null) {}

    try {}

    System.out.println ("Try...");

    Calendar calendar = Calendar.GetInstance ();

    SimpleDateFormat dateFormat =

    new SimpleDateFormat (simpleDateFormat);

    calendar.setTime (dateFormat.parse (sDate));

    Calendar.Set (Calendar.DAY_OF_WEEK, date); day = Calendar.SUNDAY

    Calendar.Set (Calendar.HOUR_OF_DAY, 0);

    Calendar.Set (Calendar.MINUTE, 0);

    Calendar.Set (Calendar.SECOND, 0);

    Calendar.Add (Calendar.DATE, 7);

    dateFormat.format (calendar.getTime ());

    try {}

    System.out.println ("try (inside)... ») ;

    "System.out.println (" new Timestamp (calendar.getTime () .getTime ()) "):" +.

    new Timestamp (calendar.getTime () .getTime ()));

    result = new Date (Timestamp (calendar.getTime () .getTime ())) new; Code does not work here.

    return the result;

    } catch (SQLException e) {}

    System.out.println ("catch (SQLException e)... ») ;

    e.printStackTrace ();

    }

    Returns a null value.

    } catch (ParseException exception) e {}

    System.out.println ("catch exception e ParseException... ») ;

    e.printStackTrace ();

    }

    Returns a null value.

    }

    Returns a null value.

    }

    Here is the result:

    try...

    Try (inside)...

    new Timestamp (calendar.getTime () .getTime ())): 2013-12-29 00:00:00.0

    catch (SQLException e)...

    java.sql.SQLException: failed initialization

    to oracle.sql.DATE. < init > (DATE.java:237)

    to oracle.jbo.domain.Date. < init > (Date.java:378)

    James

    try to convert timestamp to jbo.date as

    java.sql.Timestamp datetime =newjava.sql.Timestamp(System.currentTimeMillis());

    oracle.jbo.domain.Date daTime =new  oracle.jbo.domain.Date(datetime);

  • formatting oracle.jbo.domain.date

    Hello

    I use JDev 11.1.2.4.

    I'm trying to update VO with the current date and time by using the code below.

    DateFormat df = new SimpleDateFormat ("YYYY/MM/dd HH: mm :"); ")

    java.util.Date currentDate = new java.util.Date ();

    row.setAttribute ("Date sent", df.format (currentDate));

    However, I run error

    Houston-27023: Impossible to validate all the lines in a transaction.

    any ideas?

    Thank you

    Hello

    When you define the attribute that you do not need to set the format of datetime.

    If you want to set the attribute to current date time use this

    If the attribute is of type Timestamp, you can set date current time like that

    row.setAttribute("ShippedDate",new oracle.jbo.domain.Date(new java.sql.Timestamp(System.currentTimeMillis())));
    

    If the data type of the attribute is oracle.jbo.domain.Date you can set the date current time like that

    row.setAttribute("ShippedDate",new oracle.jbo.domain.Date(oracle.jbo.domain.Date.getCurrentDate()));
    

    and to display that date in the page with the format DD/MM/YYYY HH: mm: follow these steps:

    1 - Open the viewobject and select Date sending attribute.

    2 - starting from the indications of the UI, tab set Type-> Simple Date Format

    3. as text the value of-> MM/DD/YYYY HH: mm:

  • In general, is it better to use java.sql.Date and java.sql.Timestamp instead of oracle.jbo.domain.Date?

    Hello world

    During playback of Oracle ADF Real World Developer's Guide, I noticed the dates match occurring in JDeveloper is different from what is the list in the book. JDeveloper is failing to oracle.jbo.domain.Date, but according to the book:

    DATEjava.sql.DateDATE type is mapped to java.sql.Date if the column in the table is a no time didn't need information zone.
    DATEjava.sql.TimestampDATE type is mapped to java.sql.Timestamp if the column in the table has a component "time" and that the client needs to zone information.
    TIMESTAMPjava.sql.TimestampThe TIMESTAMP type is mapped to java.sql.Timestamp if nanosecond precision is used in the database.

    In general, is it better to use java.sql.Date and java.sql.Timestamp instead of oracle.jbo.domain.Date? Using java.sql.Date and java.sql.Timestamp could save me some headaches conversion date. And, is there a place in JDeveloper to display these maps? I looked around and didn't see anything.

    Thank you.

    James

    User, what version of jdev we are talking about?

    In GR 11, 1 material versions db types date and timestamp are mapped to types of domain data that represents a wrapper for the native data types. The reason was that the framework can work with the domain types regardless of the underlying data type.

    Since Oracle 11 GR 2 maps the types DB to java types (default selection, you can change it when you create a model project, you can set the Data Type Mapping). Once the pilot has business components define you cannot change this setting it would break existing components such as eo or vo.

    So if you are working wit 11 GR 1 subject, you must use the domain types, if you work with GR 11, 2 or 12 c, you can use the domain types, but it is recommended to use the java type mapping.

    Timo

  • conversion string in oracle.jbo.domain.Date

    Hello

    I work in jdev 11.1.1.6

    I receive as string date of UCM as string. I need to convert to oracle.jbo.domain.Date.How to achieve

    u cn do this

    DateFormat trainer;

    java.util.Date date;

    {if(aDate!=null)}

    try {}

    Formatter = new SimpleDateFormat("dd/MMM/yyyy");

    Date = formatter.parse (date);

    java.sql.Date sqlDate = new java.sql.Date (date.getTime ());

    oracle.jbo.domain.Date jboDate = new oracle.jbo.domain.Date (sqlDate);

    Return jboDate;

    }

    catch (ParseException exception) e

    {

    e.printStackTrace ();

    }

    }

  • How to page to the controller oracle.jbo.domain.date

    Hi all

    I want to get the date of my grain of table advanced to the controller. I'm date as a java.sql.Date I want to convert it to oracle.jbo.domain.Date. Pointers in it will be useful.

    Thanks in advance.

    With respect,
    Anjani.

    spend your date ViewObject, you will get it in the format jbo.domain.date

    VO. Next(). GetAttribute ("DateAttributeXXXX");

    Prasanna-

  • How to truncate oracle.jbo.domain.date

    Hello
    I have problem to convert oracle.jbo.domain.date. Now, I got the current date of pagecontext, but this is the format yyyy-mm-dd hh. I want only aaaa-mm-jj, so I want to truncate the time of oracle.jbo.domain.date. And I want to got to this Date no chain. I found Date.truncate () there, but I don't know how to use it.
    Could someone help to give me an example?

    Best regards
    Eileen

    Hello

    use,

    currentDate = am.getOADBTransaction () .getCurrentUserDate () oracle.jbo.domain.Date;
    Date testdate = (Date) currentDate.dateValue ();

    Thank you
    Gerard

  • Dynamically calculate the number of days between two dates and amounts of split

    Hello

    I have searched for a solution for this, but had no success.
    I need to show the amounts broken down by days.

    I have a table that has an amount column and start and end dates.

    I need to write a query so that the amounts will be broken evenly based on the number of days between the start date and end date.

    For example, for this line.
    insert into my_test values (' 1, '' 3-mar-2010, ' 7 - mar - 2010 ", 1000);

    the query returns this (split $1,000 over 5 days)


    ID Date amount
    1 ' 3-mar-2010' 200,00
    1 ' 4-mar-2010' 200,00
    1 ' 5-mar-2010' 200,00
    1 ' 6-mar-2010' 200,00
    1 ' 7-mar-2010' 200,00



    create table my_test)
    ID number (10),
    start_date date,
    End_date date,
    amount number (10.2)
    );


    Select * from my_test

    insert into my_test values (' 1, '' 3-mar-2010, ' 7 - mar - 2010 ", 1000);
    insert into my_test values (2, 10-mar-2010 ", 19-mar-2010", 2000);
    insert into my_test values (3, 20-mar-2010 ',' 21-mar-2010, 5000);



    Thanks in advance.

    Hello

    One way is to join a Meter of Table , a table, or (more often) a set of results includes a line for eery number 1, 2, 3,... until the maximum number of times you need to divide a line.
    For example:

    WITH     cntr     AS
    (
         SELECT     LEVEL - 1     AS n
         FROM     (  SELECT  MAX (end_date - start_date)     AS max_day_cnt
                 FROM        my_test
              )
         CONNECT BY     LEVEL <= 1 + max_day_cnt
    )
    SELECT       t.id
    ,       t.start_date + c.n                    AS dt
    ,       t.amount / (t.end_date + 1 - t.start_date)     AS amt
    FROM       my_test      t
    JOIN       cntr            c     ON     c.n <= t.end_date - t.start_date
    ORDER BY  id
    ,            dt
    ;
    

    This assumes that all dates have the same number of hours, minutes, and seconds, as is the case in your sample data.
    If this isn't the case, then use TRUNC (start_date) and TRUNC (end_date) instead of start_date and end_date or post some sample data and results if some lines do not represent a whole number of days.

  • Number of days between two Dates in the Correct month

    I am trying to write a SELECT statement that returns the number of days spent on a project.

    Here's my problem. I have a table with several columns of date (start_date, end_date, etc.) as well as several other columns. Here is an example of the table.

    PROJECT... START_DATE... END_DATE
    123 ................. 1ST JANUARY 13... 15 JANUARY 13
    456 ................. 25 JANUARY 13... FEBRUARY 5, 13
    789 ................. 30 JANUARY 13... FEBRUARY 5, 13
    999 ................. 1ST FEBRUARY 13... FEBRUARY 8, 13

    I'm counting the number of days spent on projects in each month. For example, with the above data, I would come back...

    MONTHS... PROJECT_DAYS
    Jan ............. 24
    Feb ............. 18

    I tried to use a CASE statement, but I'm having a hard time to understand. Any help would be greatly appreciated!

    Published by: 987079 on February 8, 2013 13:12

    An option would be something like

      1  with project as (
      2    select 123 project_id, date '2013-01-01' start_date, date '2013-01-15' end_date from dual union all
      3    select 456, date '2013-01-25', date '2013-02-05' from dual union all
      4    select 789, date '2013-01-30', date '2013-02-05' from dual union all
      5    select 999, date '2013-02-01', date '2013-02-08' from dual
      6  ),
      7  all_days as (
      8    select start_date + level - 1 dt
      9      from (select min(start_date) start_date,
     10                   max(end_date) end_date
     11              from project)
     12   connect by level <= end_date - start_date + 1
     13  )
     14  select trunc(dt,'MM'),
     15         count(*)
     16    from all_days ad
     17         join project p on (ad.dt between p.start_date and p.end_date)
     18   group by trunc(dt,'MM')
     19*  order by trunc(dt,'MM')
    SQL> /
    
    TRUNC(DT,'MM')        COUNT(*)
    ------------------- ----------
    2013-01-01 00:00:00         24
    2013-02-01 00:00:00         18
    

    Justin

  • Behavior of days between two dates

    Hello!
    If anyone can help? ... with differences in Date? :

    All I want is to calculate the number of days between two dates:

    InitDate has been entered as 01/10/2010 planning, to recover is 20101001
    HireDate was entered into the 1980-10-01 planning, to recover is 19801001

    I tried

    NumDays = @DATEDIFF (InitDate, HireDate, DP_DAY);

    but give me only 0 and -1.



    When I try the regular difference:

    NumDays = InitDate - HireDate;

    He returned to 30,000 (which in the example is 20101001-19801001) - which should not.


    I use Essbase/Planning 11.1.1.2, I tried also to break dates in years and months using INT and operations, but when I want to get the calendar days he is ugly. The two dates live in the same block.

    Someone at - it an idea?

    Thank you very much!

    Hello
    Here's a piece of code in my trunk of code which may help you. This assumes you have string CDF pack (https://www.samplecode.oracle.com/tracker/tracking/linkid/prpl1004/remcurreport/true/template/ViewIssue.vm/id/S441/nbrresults/9)

    var y1, y2, m1, m2, d1, d2, difx1, difx2;

    FIX (SOLUTION YOUR MEMBERS HERE)
    "BLOCK MEMBER")

    Y1=@round ("Date of 1" / 10000,0);
    Y2=@round ("Date 2" / 10000,0);
    M1=@round (("Date 1"-y1*10000)/100, 0);
    M2=@round (("Date 2"-y2*10000)/100, 0);
    D1 = ' Date of 1 "-(y1*10000+m1*100);"»
    D2 = "Date 2"-(y2*10000+m2*100); "»

    difx1=@TODATEEX ("mm/dd/yyyy",
    @JconcatStrings (@LIST (@JgetStringFromDouble (m2,@_false,@_false), ' / ', @JgetStringFromDouble (d2,@_false,@_false), ' / ', @JgetStringFromDouble (y2,@_false,@_false)))
    )
    ) ;
    difx2 = @TODATEEX ("mm/dd/yyyy", @JconcatStrings (@LIST)
    @JgetStringFromDouble (m1,@_false,@_false), ' / '.
    @JgetStringFromDouble (d1,@_false,@_false), ' / '.
    @JgetStringFromDouble (y1,@_false,@_false))
    )
    );

    diff=@DateDiff (difx2, difx1, DP_DAY);
    )
    ENDFIX

    See you soon,.
    Alp

Maybe you are looking for