Search between Two date Error

Hi,
i have create report using to table i have take search option in that report now i want to display report between two dates
How to put Between Date Quary in search option in where Clause .
My code is
select      CRM_SALES_DEALs.id,
         "CRM_SALES_CUSTOMERS"."CUSTOMER_NAME" as "CUSTOMER_NAME",
      "CRM_SALES_SALESREPS"."REP_LAST_NAME"||', '||
      "CRM_SALES_SALESREPS"."REP_FIRST_NAME" as "REP_NAME",
      "CRM_SALES_DEALS"."DEAL_NAME" as "DEAL_NAME",
      "CRM_SALES_DEALS"."EMAIL" as "EMAIL",
      "CRM_SALES_DEALS"."DEAL_CLOSE_DATE" as "DEAL_CLOSE_DATE",
      "CRM_SALES_DEALS"."DEAL_AMOUNT" as "DEAL_AMOUNT",
      "CRM_SALES_DEALS"."DEAL_PROBABILITY" as "DEAL_PROBABILITY",
      "CRM_SALES_DEAL_STATUS_CODES"."STATUS_CODE" as "STATUS_CODE" ,
         "CRM_SALES_DEALS"."DATE_OF_QUARY" as "DATE_OF_QUARY",
         "CRM_SALES_DEALS"."DEAL_SOURCE" as "DEAL_SOURCE",
         "CRM_SALES_DEALS"."DEAL_AMOUNT" *
         "CRM_SALES_DEALS"."DEAL_PROBABILITY" / 100 weighted_forecast,
(select count(*) from CRM_SALES_DEAL_products where deal_id = "CRM_SALES_DEALS".id) products,
nvl("CRM_SALES_DEALS".updated_on,"CRM_SALES_DEALS".created_on) last_changed,
t.territory_name,
CRM_SALES_DEALS.qtr, "CRM_SALES_DEALS"."CONTACT_NAME" as "CONTACT_NAME",
"CRM_SALES_DEALS"."ACTIVE_FLAG" as "ACTIVE_FLAG"
from     
"CRM_SALES_SALESREPS",
"CRM_SALES_DEAL_STATUS_CODES" ,
"CRM_SALES_CUSTOMERS",
"CRM_SALES_DEALS",
CRM_SALES_territories t
where  
CRM_SALES_customers.customer_territory_id = t.id(+) and
"CRM_SALES_DEALS"."CUSTOMER_ID"="CRM_SALES_CUSTOMERS"."ID"(+)
and      "CRM_SALES_DEALS"."DEAL_STATUS_CODE_ID"="CRM_SALES_DEAL_STATUS_CODES"."ID"(+)
and      "CRM_SALES_DEALS"."SALESREP_ID_01"="CRM_SALES_SALESREPS"."ID"(+) and "CRM_SALES_DEALS"."ACTIVE_FLAG" ='Y' and (:p1_find is null or instr(upper("CRM_SALES_CUSTOMERS"."CUSTOMER_NAME"),upper(:p1_find))>0 or instr(upper("CRM_SALES_DEALS"."DEAL_NAME"),upper(:p1_find))>0 or
instr(upper("CRM_SALES_SALESREPS"."REP_FIRST_NAME"||' '||"CRM_SALES_SALESREPS"."REP_LAST_NAME"),upper(:p1_find))>0)
and
(nvl(:P1_TERRITORY,0) = 0 or t.id= :P1_TERRITORY)
and
(nvl(:P1_ACCOUNT,0) = 0 or "CRM_SALES_CUSTOMERS".id = :P1_ACCOUNT)
and
(nvl(:P1_QUARTER,'0') = '0' or CRM_SALES_deals.qtr = :P1_QUARTER)
and
*("CRM_SALES_DEALS".created_on between :P1_CREATE_DATE and :P1_END_DATE ) >0 and*                                          *Here I have put Quary*
instr(upper("CRM_SALES_DEALS"."CREATED_ON"),upper(nvl(:P1_CREATE_DATE,"CRM_SALES_DEALS"."CREATED_ON"))) > 0
and
nvl(DEAL_PROBABILITY,10) between nvl(:P1_MINIMUM_PROBABILITY,0) and nvl(:P1_MAXIMUM_PROBABILITY,100) AND
(nvl(:P1_LEAD_SOURCE,'0') = '0' or CRM_SALES_DEALS.DEAL_SOURCE = :P1_LEAD_SOURCE)Show me Error Command not Properly Ended
How can i search Between two date In Search option.
Thanks

I'm guessing that this is Jay???
Please heed my numerous previous comments regarding formatting and those horrible full table aliases and upper case, double quoted names... Grrr...
Anyway, try this...
SELECT   CRM_SALES_DEALs.id,
         CRM_SALES_CUSTOMERS.CUSTOMER_NAME AS CUSTOMER_NAME,
            CRM_SALES_SALESREPS.REP_LAST_NAME
         || ', '
         || CRM_SALES_SALESREPS.REP_FIRST_NAME
            AS REP_NAME,
         CRM_SALES_DEALS.DEAL_NAME AS DEAL_NAME,
         CRM_SALES_DEALS.EMAIL AS EMAIL,
         CRM_SALES_DEALS.DEAL_CLOSE_DATE AS DEAL_CLOSE_DATE,
         CRM_SALES_DEALS.DEAL_AMOUNT AS DEAL_AMOUNT,
         CRM_SALES_DEALS.DEAL_PROBABILITY AS DEAL_PROBABILITY,
         CRM_SALES_DEAL_STATUS_CODES.STATUS_CODE AS STATUS_CODE,
         CRM_SALES_DEALS.DATE_OF_QUARY AS DATE_OF_QUARY,
         CRM_SALES_DEALS.DEAL_SOURCE AS DEAL_SOURCE,
         CRM_SALES_DEALS.DEAL_AMOUNT * CRM_SALES_DEALS.DEAL_PROBABILITY / 100
            weighted_forecast,
         (SELECT   COUNT ( * )
            FROM   CRM_SALES_DEAL_products
           WHERE   deal_id = CRM_SALES_DEALS.id)
            products,
         NVL (CRM_SALES_DEALS.updated_on, CRM_SALES_DEALS.created_on)
            last_changed,
         t.territory_name,
         CRM_SALES_DEALS.qtr,
         CRM_SALES_DEALS.CONTACT_NAME AS CONTACT_NAME,
         CRM_SALES_DEALS.ACTIVE_FLAG AS ACTIVE_FLAG
  FROM   CRM_SALES_SALESREPS,
         CRM_SALES_DEAL_STATUS_CODES,
         CRM_SALES_CUSTOMERS,
         CRM_SALES_DEALS,
         CRM_SALES_territories t
WHERE   CRM_SALES_customers.customer_territory_id = t.id(+)
         AND CRM_SALES_DEALS.CUSTOMER_ID = CRM_SALES_CUSTOMERS.ID(+)
         AND CRM_SALES_DEALS.DEAL_STATUS_CODE_ID =
               CRM_SALES_DEAL_STATUS_CODES.ID(+)
         AND CRM_SALES_DEALS.SALESREP_ID_01 = CRM_SALES_SALESREPS.ID(+)
         AND CRM_SALES_DEALS.ACTIVE_FLAG = 'Y'
         AND (:p1_find IS NULL
              OR INSTR (UPPER (CRM_SALES_CUSTOMERS.CUSTOMER_NAME),
                        UPPER (:p1_find)) > 0
              OR INSTR (UPPER (CRM_SALES_DEALS.DEAL_NAME), UPPER (:p1_find)) >
                   0
              OR INSTR (
                   UPPER(   CRM_SALES_SALESREPS.REP_FIRST_NAME
                         || ' '
                         || CRM_SALES_SALESREPS.REP_LAST_NAME),
                   UPPER (:p1_find)
                ) > 0)
         AND (NVL (:P1_TERRITORY, 0) = 0 OR t.id = :P1_TERRITORY)
         AND (NVL (:P1_ACCOUNT, 0) = 0
              OR CRM_SALES_CUSTOMERS.id = :P1_ACCOUNT)
         AND (NVL (:P1_QUARTER, '0') = '0'
              OR CRM_SALES_deals.qtr = :P1_QUARTER)
         AND CRM_SALES_DEALS.created_on BETWEEN :P1_CREATE_DATE
                                             AND  :P1_END_DATE
         AND INSTR (
               UPPER (CRM_SALES_DEALS.CREATED_ON),
               UPPER (NVL (:P1_CREATE_DATE, CRM_SALES_DEALS.CREATED_ON))
            ) > 0
         AND NVL (DEAL_PROBABILITY, 10) BETWEEN NVL (:P1_MINIMUM_PROBABILITY,
                                                     0)
                                            AND  NVL (
                                                    :P1_MAXIMUM_PROBABILITY,
                                                    100
         AND (NVL (:P1_LEAD_SOURCE, '0') = '0'
              OR CRM_SALES_DEALS.DEAL_SOURCE = :P1_LEAD_SOURCE)Cheers
Ben

Similar Messages

  • How to make search between two dates accept null not obligatory search proplem

    Hi guys when i search record between two dates it works ok success but you must enter date from and dateto first to  to make search
    i will show what i need from this example
    I need to search dynamic by 4 textbox
    1-datefrom
    2-dateto
    3-EmployeeNo
    4-EmployeeName
    but search i need must be dynamic meaning
    if i enter employee no only give me employee no found in database
    if i enter employee name give me employees found with this name using like
    if i enter all 4 text box null and enter button search get all data
    but i have proplem in this query when i need to search by click search button
    i must write date from and date to firstly then write employee no or employee name if i need to search
    so that i need to search by employee no alone or employee name alone without using date from and date to
    And if i search without using datefrom and dateto it give me message error 'string wasnot recognized as valid datetime"
    my stored procedure and code as following :
    ALTER proc [dbo].[CollectsearchData]
    @StartDate datetime,
    @EndDate datetime,
    @EmployeeID  NVARCHAR(50),
    @EmployeeName  nvarchar(50)
    as
    Begin
    Declare @SQLQuery as nvarchar(2000)
    SET @SQLQuery ='SELECT * from ViewEmployeeTest Where (1=1)'
    If (@StartDate is not NULL)
    Set @SQLQuery = @SQLQuery + ' And (joindate >= '''+ Cast(@StartDate as varchar(100))+''')'
    If (@EndDate is not NULL)
    Set @SQLQuery = @SQLQuery + ' And (joindate <= '''+ Cast(@EndDate as varchar(100))+''')' 
    If @EmployeeID <>''
    Set @SQLQuery = @SQLQuery + 'And (EmployeeID = '+ @EmployeeID+') '
    If @EmployeeName Is Not Null
    Set @SQLQuery = @SQLQuery + ' AND (DriverName LIKE
    ''%'+@EmployeeName+'%'') '
    Print @sqlQuery
    Exec (@SQLQuery) 
    End
    Function using
    public DataTable SearchDataA(string ConnectionString,string EmployeeNo,string EmployeeName, DateTime StartDate, DateTime EndDate)
    SqlConnection con = new SqlConnection(ConnectionString);
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = con;
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = "CollectsearchData";//work
    cmd.Parameters.Add("@StartDate", SqlDbType.DateTime);
    cmd.Parameters.Add("@EndDate", SqlDbType.DateTime);
    cmd.Parameters.Add("@EmployeeID", SqlDbType.NVarChar, 50);
    cmd.Parameters.Add("@EmployeeName", SqlDbType.NVarChar, 50);
    cmd.Parameters["@StartDate"].Value = StartDate;
    cmd.Parameters["@EndDate"].Value = EndDate;
    cmd.Parameters["@EmployeeID"].Value = EmployeeNo;
    cmd.Parameters["@EmployeeName"].Value = EmployeeName;
    SqlDataAdapter da = new SqlDataAdapter();
    da.SelectCommand = cmd;
    DataSet ds = new DataSet();
    da.Fill(ds);
    DataTable dt = ds.Tables[0];
    return dt;
    interface button search
     try
    CultureInfo ukCulture = new CultureInfo("en-GB");             
    FleetManagment.Fleet fleet = new FleetManagment.Fleet();
    DataTable Table = fleet.SearchDataA("Data Source=" + value1 + ";Initial Catalog=" + value2 + ";User ID=" + value3 + ";Password=" + value4 + "",textBox3.Text,textBox4.Text, DateTime.Parse(textBox1.Text,
    ukCulture.DateTimeFormat), Convert.ToDateTime(textBox2.Text, ukCulture.DateTimeFormat));
    dataGridView1.DataSource = Table;
    dataGridView1.Refresh();
    catch (Exception ex)
    MessageBox.Show(ex + "error");

    Yes, the below code should not be passed any value: (I am not sure of the syntax in .NET,Sorry) 
    --If startdate len is 0 - do not assign this value
    cmd.Parameters["@StartDate"].Value = StartDate;
    --If endate len is 0 - do not assign this value
    cmd.Parameters["@EndDate"].Value = EndDate;

  • Search between two dates

    Hi,
    I have a fields start_date(Literal Date) and end date (Literal Date) in my MDM table.
    Could any one give me a clue how to search values between these two dates from java program to this type of columns.
    Waiting for reply.

    Hi,
    Following is a snippet of code for searching a range on a date/time field in an MDM repository.
    In the following code, the table we are searching on is called "Products", and has two fields: "Part Number" and "Update Date" which is the date field. We will search for all products with "Update Date" between 2006-1-1 and 2006-1-31. (Remember in Java that MONTHS are from 0-11, and NOT 1-12).
    ============= START OF CODE =================
                        // Create a ResultSetDefinition
                        ResultSetDefinition rsd = new ResultSetDefinition("Products");
                        rsd.AddField("Part Number");
                        rsd.AddField("Update Date");
                        // Create a Search object
                        Search search = new Search("Products");
                        FreeFormTableParameter fftp = search.GetParameters().NewFreeFormTableParameter("Products");
                        FreeFormParameterField ffpf = new FreeFormParameterField("Update Date");
                        FreeFormParameter ffp = new FreeFormParameter();
                        ffpf.Add(new DateTimeParameter(2006, 0, 1, 0, 0, 0, 0, FreeFormParameter.GreaterThanOrEqualToSearchType));
                        ffpf.Add(new DateTimeParameter(2006, 0, 31, 0, 0, 0, 0, FreeFormParameter.LessThanOrEqualToSearchType));
                        ffpf.SetSearchOperator(FreeFormParameterField.SEARCH_OPERATOR_AND);
                        fftp.Add(ffpf);
                        // Get the results using the search                    
                        A2iResultSet rs = catalog.GetResultSet(search, rsd, "Part Number", true, 0);
                        System.out.println("Num found = " + rs.GetRecordCount());
    ============= END OF CODE =================
    Hope this helps,
    Walter

  • Query to search between two specific dates and time period

    Hi,
    Need a query to search between two particular dates and time period
    Like i want to search table having one date field .
    Suppose the date range is '01-JUL-06' and '01-AUG-06' and time frame
    is 23:00:00 to 08:00:00
    i.e i want to search between dates 01 july to 01 aug and also within the time frame i.e 23:00 to 08:00 hrs only

    The general principle is
    SELECT * FROM your_table
    WHERE some_date BEWTEEN to_date('01-JUL-06') and to_date('01-AUG-06' )+0.99999
    AND  ( some_date <= trunc(some_date)+8/24
               OR  some_date >= trunc(some_date)+23/24 )
    /Cheers, APC

  • 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 two dates

    Hi
    I have two date fields in the ODS..Both are characterists
    1. Requested delivery date
    2. Actual shipment end date.
    I would like to create a calculated KF  field for the difference between two dates in a query.
    How can I accomplish it?
    Regards

    You have to make Expiration data as nav attribute and create a formula variable then only this date can be used in calculations.
    refer this How to...for the same
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/72f4a790-0201-0010-5b89-a42a32223ffc
    later you can try to calculate difference between dates!
    Re: calculating the difference between two dates
    Please search in forum with 'difference between two dates'.You will find lots of good posts on this issue!
    hope this helps
    Regards

  • Calculate Difference in Days Between two Dates

    Hi,
    I'm trying to figure out how to calculate the difference in days between two dates using JavaScript in LiveCycle. (JavaScript knowledge = minimal)
    Where "Start_Date" and "Current_Date" are the names of the two dates in the Hierarchy palette. (both Date/Time Field)
    *Current date is using the Object > Value > Runtime Property > Current Date/Time
    I need a Text or Numeric field displaying the difference in days. (Difference_in_Days)
    I've noticed the following code being pretty standard amongst other responses:
    var 
    Start_Date = new Date(Start_Date);
    var 
    Current_Date = new Date(Current_Date);
    var 
    nAgeMilliseconds = Current_Date.getTime() - Start_Date.getTime();
    var 
    nMilliSecondsPerYear = 365 * 24 * 60 * 60 * 1000;
    I know there's code missing, and the above code might not be correct.
    Please advise.

    Where "DateField01" = user entered date field
    Where "DateFiled02" = Current Date/Time (Runtime Property)
    where "Subform" = the subform containing DateField01
    My script now resembles:
    var oneDay = 24*60*60*1000;
    var firstDate = new Date(Subform.DateField01.rawValue);
    var secondDate = new Date(DateField02.rawValue);  
    (firstDate.getTime() - secondDate.getTime()) / oneDay;
    I tried adding:
    app.alert(String(diffDays));
    Although I assume the reason I didn't get an error is because DateField01 is empty when the form is opened.
    If I swap in actual dates instead of fields it works perfectly.
    When I use the fields I have no information populating after I enter a date in "DateField01"

  • How to calculate number of days between two date in Template design?

    Hello guys
    I have a situation where I have to create a template that returns data, and one of the thing of the existing report is that there is a column that is actually the number of days between start date and end date columns..
    So in template, how would I be able to do the same? I have start date and end date columns on the template, now when I created another column using expression like end date - start date and preview the template, I am getting errors saying :
    Caused by: oracle.xdo.parser.v2.XPathException: Cannot convert 03/31/2009 to number.
         at oracle.xdo.parser.v2.XSLStylesheet.flushErrors(XSLStylesheet.java:1534)
         at oracle.xdo.parser.v2.XSLStylesheet.execute(XSLStylesheet.java:521)
         at oracle.xdo.parser.v2.XSLStylesheet.execute(XSLStylesheet.java:489)
         at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:271)
         at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:155)
         at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:192)
    Please advice
    Thanks

    Hi
    There is an extension function you can use, from the javadoc:
    date_diff
    public static long date_diff(java.lang.String format,
    java.lang.String fromDate,
    java.lang.String toDate,
    java.lang.String locStr,
    java.lang.String tzID)
    Method to get the difference between two dates in the given locale. The dates need to be in "yyyy-MM-dd" format. This function supports only Gregorian calendar.
    Parameters:
    format - the format to which the difference is required; allowed formats are y (for Year), m(for month), w(for week), d(for day), h(for hour), mi(for minute), s(for seconds) and ms(for milliseconds)
    fromDate - the first date
    toDate - the second date
    locStr - locale string -> lang-Territory
    tzID - timezone ID ->http://java.sun.com/j2se/1.4.2/docs/api/java/util/TimeZone.html
    Returns:
    the difference in dates in the desired format
    For example
    <?xdoxslt:date_diff(‘d’,’2009-09-14’, ‘2009-09-20’,’en-US’,1)?>
    give a result of 6
    You can substitute in columns for the dates, just remember the date format required.
    Regards
    Tim

  • Number weeks between two dates which are in same year or different year

    Hi,
    how to calculate the number of weeks between two dates?
    eg. '17-mar-2013' and '27-jun-2013' or '15-jun-2013' and '25-mar-2014'
    Thanks in advance.
    lukx

    A not tested "integer arithmetic" example (to be adjusted to your conceptions if feasible) covering only both dates in the same year and dates in successive years examples.
    consider Setting Up a Globalization Support Environment
    select case when substr(:start_date,1,4) = substr(:end_date,1,4)
                then to_number(to_char(to_date(:end_date,'yyyymmdd'),'iw')) -
                     to_number(to_char(to_date(:start_date,'yyyymmdd'),'iw'))
                when to_number(substr(:end_date,1,4)) - to_number(substr(:start_date,1,4)) = 1
                then to_number(to_char(trunc(to_date(:end_date,'yyyymmdd'),'yyyy') - 1,'iw')) -
                     to_number(to_char(to_date(:start_date,'yyyymmdd'),'iw')) +
                     to_number(to_char(to_date(:end_date,'yyyymmdd'),'iw')) + 1
           end iso_weeks_between
      from dual
    Regards
    Etbin
    the following seems to work for iso weeks treated as buckets
    with
    t as
    (select date '2013-03-17' d1,date '2013-06-17' d2 from dual union all
    select date '2003-12-31',date '2004-01-01' from dual union all
    select date '2004-12-31',date '2005-01-01' from dual union all
    select date '2005-12-31',date '2006-01-01' from dual union all
    select date '2013-12-29',date '2013-12-30' from dual union all
    select date '2016-01-03',date '2016-01-04' from dual union all
    select date '2013-06-15',date '2014-03-25' from dual
    select d1,
           to_number(to_char(d1,'iw')) low_iso_week,
           d2,
           to_number(to_char(d2,'iw')) high_iso_week,
           to_number(to_char(d2,'iw')) - to_number(to_char(d1,'iw')) iso_week_diff,
           case when to_number(to_char(d2,'iw')) - to_number(to_char(d1,'iw')) < 0
                then to_number(to_char(d2,'iw')) - to_number(to_char(d1,'iw')) +
                     case when to_char(trunc(d2,'yyyy'),'iw') = '01'
                          then 52
                          else to_number(to_char(trunc(d2,'yyyy'),'iw'))
                     end
                else to_number(to_char(d2,'iw')) - to_number(to_char(d1,'iw'))
           end iso_weeks_apart
      from t
    Message was edited by: Etbin
    with no Database at hand pencil and paper is too error prone to figure out iso week changes for varioud december - january periods

  • Difference between two dates: a complete solution

    There have been many posts asking how to get the number of days between two dates. There is no method in java like the VB method dateDiff(), and there is only the method date.getTime() which gives you the number of milliseconds since Jan 1 1970, the Epoch. I have not seen a solution that makes use of the fact that there are 86400000 milliseconds per day, only when trying to get the number of days , i.e. multiples of 24 hours between two millisecond points in time.
    So what if date1 was Oct 26th 11.30pm and date2 was Oct 27th 12.30am? If you get the millisecond difference, and divide by 86400000, you do not notice that these two times are on separate days, but only one hour apart.
    My solution takes account of the modulo (%) function. If you use the date.getTime() method, and use % 86400000 on this number of milliseconds, it will tell you how far (milliseconds) this date is into this day, after 12am. If you subtract this amount from the total number of milliseconds, then divide by 86400000, this will give you the number of days after the Epoch, so you are able to know which day the millisecond time is in. If you want to know the days between two millisecond times, this will tell you, whereas just dividing by 86400000, will not, and may be misleading.
    I think this could be incorporated into the Date class easily. There are some problems though, as not every day has 86400000 milliseconds, if you are talking about days when Daylight Saying Time begins or ends. Doing calculations like that will create errors, unless you know whether each date is in Daylight Saving Time or not. Leap years are OK, unless want to work out the number of years from the number of days by dividing by 365, as calculating numbers of days is only done by looking at a 24 hour time period. However where 'leap seconds' have been added, like once every ten years, there may be small errors. This was not included in anyone elses calculations.
    So the calculation would go like this:
    public class BetterDate extends Date
    public int dayDifference(Date d)
    long time = this.getTime() ; // gets milliseconds
    long timed = d.getTime() ; // gets milliseconds of other date
    int days = (time - (time % 86400000))/86400000 ; // number of days
    int daysd = (timed - (timed % 86400000))/86400000 ; // number of days of other date
    int difference = daysd - days ; // difference in days between two dates
    return difference ;
    If you want you can use the value (time % 86400000), and modulo this amount with the number of milliseconds in one hour, then subtract the result from the (time % 86400000) and divide by the millliseconds in one hour to give you the number of hours, but there are JDK functions that you can use to get the hour if needed.
    This method is not perfect, but for most cases will get you the difference in days between two dates.
    James

    Hi James,
    I tried out your solution, but it seems to fail on dates without times. I tries the difference between 31/03/2002 and 01/04/2002 and the result is 0. I guess it is because the times are assumed to be 00:00 as no times are mentioned and 31st March I believe is the date when DST change will take place this year. If I set the two times as well to a time much later than midnight for example 0600 then I seem to get the right answer.
    Joag
    There have been many posts asking how to get the
    number of days between two dates. There is no method
    in java like the VB method dateDiff(), and there is
    only the method date.getTime() which gives you the
    number of milliseconds since Jan 1 1970, the Epoch. I
    have not seen a solution that makes use of the fact
    that there are 86400000 milliseconds per day, only
    when trying to get the number of days , i.e. multiples
    of 24 hours between two millisecond points in time.
    So what if date1 was Oct 26th 11.30pm and date2 was
    Oct 27th 12.30am? If you get the millisecond
    difference, and divide by 86400000, you do not notice
    that these two times are on separate days, but only
    one hour apart.
    My solution takes account of the modulo (%) function.
    If you use the date.getTime() method, and use %
    86400000 on this number of milliseconds, it will tell
    you how far (milliseconds) this date is into this day,
    after 12am. If you subtract this amount from the total
    number of milliseconds, then divide by 86400000, this
    will give you the number of days after the Epoch, so
    you are able to know which day the millisecond time is
    in. If you want to know the days between two
    millisecond times, this will tell you, whereas just
    dividing by 86400000, will not, and may be
    misleading.
    I think this could be incorporated into the Date class
    easily. There are some problems though, as not every
    day has 86400000 milliseconds, if you are talking
    about days when Daylight Saying Time begins or ends.
    Doing calculations like that will create errors,
    unless you know whether each date is in Daylight
    Saving Time or not. Leap years are OK, unless want to
    work out the number of years from the number of days
    by dividing by 365, as calculating numbers of days is
    only done by looking at a 24 hour time period. However
    where 'leap seconds' have been added, like once every
    ten years, there may be small errors. This was not
    included in anyone elses calculations.
    So the calculation would go like this:
    public class BetterDate extends Date
    public int dayDifference(Date d)
    long time = this.getTime() ; // gets milliseconds
    long timed = d.getTime() ; // gets milliseconds of
    other date
    int days = (time - (time % 86400000))/86400000 ; //
    number of days
    int daysd = (timed - (timed % 86400000))/86400000 ; //
    number of days of other date
    int difference = daysd - days ; // difference in days
    between two dates
    return difference ;
    If you want you can use the value (time % 86400000),
    and modulo this amount with the number of milliseconds
    in one hour, then subtract the result from the (time %
    86400000) and divide by the millliseconds in one hour
    to give you the number of hours, but there are JDK
    functions that you can use to get the hour if needed.
    This method is not perfect, but for most cases will
    get you the difference in days between two dates.
    James

  • Count days between two dates without weekend

    Hi,
    I need a solution in query or another thread, that returns the count of days between two dates without consider weekend (saturday and sunday) , I have the columns of type Date, and the return need in format of hours in one column hh:mm:ss and days in another column.
    Regards
    Jonas

    Hi and welcome to the forum.
    Keep in mind that you can do a search on this forum.
    Your question has been asked before.
    Some other pointers:
    http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551242712657900129
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:185012348071

  • How to query the number of working days between two dates

    I'm looking for a solution to calculate the number of <i>working</i> days between two dates that I can use in a formated search. 
    Calculating the total number of days is pretty straight forward but does anyone know how to take into account the settings in the HLD1 (Holiday Dates) table?

    Hi Eric,
    If you are purely looking to exclude holidays defined in the HLD1 table, then you should be able to do it with the following query
    NOTE: The following query is an example using OINV table and the fields DOCDATE and DOCDUEDATE for a Particular DOCNUM  'xxx'
    If you planning to use within the SAP module then replace DOCDATE and DOCDUEDATE with dynamic field references $[$x.x.x]
    SELECT DATEDIFF(DAY,T0.DOCDATE,T0.DOCDUEDATE)-
    (SELECT COUNT(STRDATE) FROM HLD1 WHERE STRDATE >= T0.DOCDATE AND STRDATE <= T0.DOCDUEDATE)
    FROM OINV T0
    WHERE T0.DOCNUM = xxx
    Best Wishes
    Suda

  • To find difference between two dates

    Hi all,
    I am new to this forum and oracle.
    I want to get the difference between two dates. My query is as below...
    sqlserver_utilities.datediff('YY', startdate,enddate)
    I want the difference in year.
    Please help me. It's really urgent.
    Thanks in advance.
    Regards,
    Inam

    Select to_char(enddate,'YY') - to_char(startdate,'YY') fromPLEASE don't do that. There are so many things wrong with it...
    for example:
    1). Why are you subtracting character data types?
    2). What if the start date is 1999 and the end date is 2000? Do you expect to get a difference of -1?
    3). What if the start date is 1 Jan 2000 and the end date is 31 Dec 2000? Do you expect to get 0 instead of 1 or .997?
    4). Why would you convert dates to something else when they are inherently subtractable.
    5). There are obvious points in the OP's "specification" that are vague - the best thing (after telling them to search, of course since this has been answered a million times already) would be to try to clarify the spec.
    John

  • Removing Weekends in between two dates

    Hi,
    I need to get the number of days in between two dates excluding the weekends.
    Does anyone know how to do this?
    Thanks.

    Here's a search of the forum for "difference dates". At least the first three questions are identical to yours.
    http://search.java.sun.com/Search/java?col=javafrm&qp=%2Bforum%3A31&qt=difference+dates&x=12&y=10

  • Working days between two date fields and Changing Factory Calendar

    Hi,
    I have to calculate working days between two date fields excluding the weekends and public holidays for Switzerland.
    I have written the routine using factory calender and its working fine except for two problems now:
    1. If any one of the date field is empty then teh rsult should be zero.
    2. And the below code is working from 1996 but my cleints wants it to work for years before 1996 as well.
    I also tried to change the Start date in SCAL for factory calendar but it says enter values between 1995 to 2020.
    I am new to ABAP. Please help me how i can achieve these for below code.
    DATA: IT_HOLIDAYS type TABLE OF ISCAL_DAY,
          IS_HOLIDAYS TYPE ISCAL_DAY.
    DATA: T_DATE TYPE SY-DATUM,
          P_DATE TYPE SY-DATUM.
    DATA : X_DATE(4) TYPE C.
    DATA: CNT TYPE I.
    REFRESH : IT_HOLIDAYS.
    CLEAR : IT_HOLIDAYS.
    T_DATE = SOURCE_FIELDS-/BIC/ZCCCHP812.
    P_DATE = SOURCE_FIELDS-/BIC/ZCCCHP810.
    CALL FUNCTION 'HOLIDAY_GET'
    EXPORTING
    HOLIDAY_CALENDAR = 'CH'
    FACTORY_CALENDAR = 'CH'
    DATE_FROM = P_DATE
    DATE_TO   = T_DATE
    TABLES
    HOLIDAYS = IT_HOLIDAYS
    EXCEPTIONS
    FACTORY_CALENDAR_NOT_FOUND = 1
    HOLIDAY_CALENDAR_NOT_FOUND = 2
    DATE_HAS_INVALID_FORMAT = 3
    DATE_INCONSISTENCY = 4
    OTHERS = 5.
    DESCRIBE TABLE IT_HOLIDAYS LINES CNT.
    X_DATE = T_DATE - P_DATE - CNT.
    RESULT = X_DATE.
    Please help
    Regards
    Zabina
    Edited by: Syed786 on Nov 2, 2011 9:15 AM

    Hi Zabina,
    Try this function module  'DURATION_DETERMINE'.
    Give the factory calendar and unit as DAY
    With regards,
    Rajesh

Maybe you are looking for

  • Extended Notifications: how to change the URL link

    Hello, We are on ECC6. We use Extended Notifications to alert users to the presence of new workitems, but when they click on the link to execute the workitem, they're presented with the login screen. We have been able to send emails from workflow whi

  • Operation could not be completed - GIF file

    Not sure why i am having this issue with this file. i have had they same issue with other files too, seems to always be the GIF format... If i enter the folder, or click the image or unselect the image... doesn't matter what i do this message keeps p

  • Multiple Script Logics in Default Logic.. order of execution... Commit

    Hi, I have a situation where I need to perform two activities... i) Perform a multiplication operation on the data input by the user - Script Logic A ii) Send the data at a summary level to another application. - Script Logic B Both Script logics are

  • To use IDOC or SRM?

    Hello - I have a scenario where i have Purchase Orders created in R/3 through SRM. Until i found the pre-delivered content i thought to use IDOCS in R/3 to generate my xml file output. Now, my question is which option should i go with 1) R/3 using ID

  • HT202716 Still having problems with Crackle on apple T.V

    when I bring up crackle on My apple T.V , it ask Me to enter a code ? I am not able tipe the code with My apple T.V ? any idea's . there's no problem with My I Pad or I Mac !