How to compare date range ?

hi, good day , i need some idea on my issue
scenario :
i need to know if given a new date range, and check whether this new date range is fall into between the date range
for example ,
new_start_date = 15/05/2006, new_end_date = 01/09/2006
existing start_date = 20/02/2006 , existing end_date = 11/07/2006 so in this case , new start and end date have fall into existing start and end date range, cause it should not interlapse the date range
- in short, new start_date and end_date cannot in between of existing start_date and end_date , how i write a algorithm on this ? thank you for guidance

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
* DateSample.java
* Created on February 9, 2006, 10:09 AM
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
* @author krichard
public class DateSample {
     *  new_start_date = 15/05/2006, new_end_date = 01/09/2006
     *  existing start_date = 20/02/2006 , existing end_date = 11/07/2006
    /** Creates a new instance of DateSample */
    public DateSample() {
        String existingStartDateStr = "20/02/2006" ;
        String existingEndDateStr = "11/07/2006" ;
        String newStartDateStr = "15/05/2006" ;
        String newEndDateStr = "01/09/2006" ;
        SimpleDateFormat dateUtil = new SimpleDateFormat("dd/MM/yyyy") ;
        try {
            Date existingStartDate = dateUtil.parse(existingStartDateStr);
            Date existingEndDate = dateUtil.parse(existingEndDateStr);
            Date newStartDate = dateUtil.parse(newStartDateStr);
            Date newEndDate = dateUtil.parse(newEndDateStr);
            boolean newStartCheck = existingStartDate.before(newStartDate) && existingEndDate.after(newStartDate);
            boolean newEndCheck = existingStartDate.before(newEndDate) && existingEndDate.after(newEndDate);
            boolean inBetween = newStartCheck & newEndCheck ;
            System.out.println("Existing::"+existingStartDate+" - " +existingEndDate);
            System.out.println("New::"+newStartDate+" - " +newEndDate);
            System.out.println("It is "+inBetween+" that the new dates are in between the existing ones.");
        } catch (ParseException ex) {
            ex.printStackTrace();
     * @param args the command line arguments
    public static void main(String[] args) {
        new DateSample() ;
}

Similar Messages

  • How to compare date which is greatest date

    iam new to sql
    how to compare date which date is greatest date with example
    can i use to_char to compare date
    SELECT eno, ename, GREATEST (TBLE.MAX1, TBLE.MAX2) recent_date "
                   FROM (SELECT TBLA.eno, TBLA.ename, "
                   MAX (TO_CHAR (TBL.date1, 'MM/DD/YYYY HH24:MI') "
                   ) MAX1, "
                   MAX (TO_CHAR (TBL.date2, 'MM/DD/YYYY HH24:MI') "
                   ) MAX2 "
                   FROM dual TBL, dual2 TBLA
    in above query if any one of the date having null value then recent_date is showing 'null'
    and also it showing wrong value
    example
    date1='08-22-2009' and date2='01-23-2010' then it showing wrong recent_datel ike='08-22-2009'
    as according my knowledge it is comparing with month it sholud not be like this wat i have to do pls explain with example my o/p should come for recent_date like =''01-23-2010''
    Edited by: user9112274 on Aug 27, 2010 5:31 AM

    Hi,
    there are numerous ways to compare dates, i give you some examples:
    with data_Sample as
    (select to_date('01-jan-2001','dd-mon-yyyy') d1, to_date('01-mar-2002','dd-mon-yyyy') d2, to_date('03-feb-2002','dd-mon-yyyy') d3 from dual)
    select greatest(d1,d2,d3) from data_Sample
    GREATEST(D1,D2,D3)
    3/1/2002
    with data_Sample as
    (select to_date('01-jan-2001','dd-mon-yyyy') d1 from dual union all
    select to_date('01-mar-2002','dd-mon-yyyy')   from dual union all
    select to_date('03-feb-2002','dd-mon-yyyy')  from dual)
    select max(d1) from data_Sample
    MAX(D1)
    3/1/2002
    declare
    d1 date :=to_date('01-jan-2001','dd-mon-yyyy');
    d2 date :=to_date('01-jan-2001','dd-mon-yyyy');
    begin
    if d1>d2 then
    dbms_output.PUT_LINE('d1 greater than d2');
    else
    dbms_output.PUT_LINE('d1 less or equql than d2');
    end if;
    end;
    output:
    d1 less or equal than d2now concerning your question:
    >
    can i use to_char to compare date
    >
    If you have date data types : don't convert them.
    if you have no choice, use something like:
    if to_char(d1,'YYYYMMDD') > to_char(d2,'YYYYMMDD') then
    else
    end if;Take care when you convert a date into a char format it becomes string comparison (with all it implies) (It's the reason why i've use an explicit mask format).

  • How to compare date and time together

    Hi,
    How to compare Date and Time together?
    For example in a database table there are two fields rundate and runtime.  I want to compare these two with perticular date and time in the program.  Like, I want to pull all the records where the records's date and time are less than a perticular date and time in the program.
    Hope the question is clear...
    Thanks.
    Kavita

    Hi Kavita
    There is no as such Date and Time Comparision FM in Standard SAP  But You can define your own like this
    <b>FUNCTION ZAV4_COMPAREDATETIME.
    ""Lokale Schnittstelle:
    *"  IMPORTING
    *"     REFERENCE(DATE1) TYPE  DATS
    *"     REFERENCE(TIME1) TYPE  TIMS
    *"     REFERENCE(DATE2) TYPE  DATS
    *"     REFERENCE(TIME2) TYPE  TIMS
    *"  EXPORTING
    *"     VALUE(TWOISMORETOPICAL) TYPE  C
      twoismoretopical = ''.
      if date2 > date1.
        twoismoretopical = 'X'.
      else.
         if date2 = date1 and time2 > time1.
           twoismoretopical = 'X'.
         endif.
      endif.
    ENDFUNCTION.</b>
    Regards
    Mithlesh

  • Table_comparison - how to compare data at a high level

    Hi,
    I have to do data validation at a high level between two tables that I am loading.
    I am trying to use table_comparion transform but the problem is that my target table is at a much lower level than at which I want to compare data. So it has many more columns (both key and data fields) than what I want to compare.
    Does the output of query transform ( which I am using as input into table_comparion) be in the exact same format as comparion table? If not, then can somebody suggest me something else.
    Or how can I compare output of two query transforms ?
    Thanks,
    Saurabh Bansal

    Dear Saurabh,
    Not sure if you have already got the solution to this. If yes please close the thread.
    If not, i would suggest you can use the validation rule to compare the two tables and then based on the PASS or FAIL result can check what needs to be done on the output.
    Do post back if you have got the solution or you need any furthur help or else close the question.
    regards,
    Den

  • How to compare dates in Crystal Reports 2008

    Hello,
    I cannot figure out how to compare the dates in the Crystal reports.
    I need all dates that are in the future to be displayed with the green font.
    So in the formula for the font for this texbox I've tried to use different
    formulas like:
    If DateDiff("d", CurrentDate, {DevelopmentTracking_SELECT.Anticipated}) > 1
    Then
         crGreen
    or
    If {DevelopmentTracking_SELECT.Anticipated} > CurrentDate Then
         crGreen
    (where DevelopmentTracking_SELECT is the stored procedure, and Anticipated
    is a date field).
    None of them worked. All dates are treated like they were in the past
    comparing to the CurrentDate. If I reverse these formulas like:
    If {DevelopmentTracking_SELECT.Anticipated} < CurrentDate Then
         crGreen
    then all dates turn to green, otherwise they always stay black.
    What could be a problem here?
    I would appreciate your help.
    Thank you.

    OK, got it, thank you. It worked.
    However, I also need to use another field value which is not on the report, like this:
    If CurrentFieldValue < CurrentDate And {DevelopmentTracking_SELECT.Completed} = False Then
    crRed
    DevelopmentTracking_SELECT.Completed is not on the report.
    Is it possible to use it with the cross-tab?

  • How to prompt date range for a single column in reports

    Hi All,
    I am having a prompt which shows from date and to date, both these columns will come from day column of calendar .We want that our report values should be between the from date and to date.Can someone tell me how can this be achieved.Because if we build a report we will pull day column from calendar and say its prompted.How can we get the condition that day clumn should be between from date and to date of prompt.
    Thanks and Regards,
    Amrit

    Hi vineet,
    Thanks for your reply
    I am having one prompt where we will have two columns from date and to date, both these columns are coming from same column called day in mth_calendar.I am having 1 report where the date range should lie between from date and to date of prompt.In this case should I use your second suggestion or the first one.
    Thanks,
    Amrit

  • How to compare Date in the TextField or DateTime with Date/Time field?

    Hi All,
    I am facing an issue with respect Date comparinson. I tried to look into entire discussions but failed to get the answer.
    My issue is: I wanted to comparet Date/time field value with Date value which is in TextField.
    The functionality of my form is:
    I have dropdown list which lists the registered customer ids binded to XML Datasource. On selection of the customer id from the dropdown I am displaying customer registration date in the TextField or say Date/Time field as below code in dropdown change event.
    RegistrationDetails.PurchaseEntry.txtRegDate.rawValue = regDataNode.CREATION_DATE.value; (this is TextField control)
    In form I have an Date/Time field in which use will select the date of item purchase. In the validation part I want to make sure that, the purchase date selected in Date/Time field must be greater than the Customer Registraiton Date. I able to compare if the customer selects the date from two different Date/Time fields. But how to compare the dates which one is in Date/Time field and Date is in TextField?
    I have tried using Num2Date and Date2Num with "YYYY-MM-DD"  format to compare but not succeed!
    Can you guys help me in this? Thanks in advance
    Regards.

    Hi,
    Yes, I am able to display the date which I have assigned to the text box. In the message box it show the value as '31/05/2009', since in this format i am assigining the date in the text box.
    Here is the code which I am assigning the value:
    RegistrationDetails.PurchaseEntry.txtRegDate.rawValue = regDataNode.CREATION_DATE.value;
    Do I need to change the format while assigning value in text box?
    You have told that, you have attached your test form, nothing is the reply. Can you repost the file?
    Regards.

  • How to compare date with char

    hi
    i am having date from and date to feilds in my overtime element.i want to do the validation on these dates the the dates do not overlap or duplicated.the input value date from and date to are stored in database as varchar2 in the format yyyy/mm/dd 00:00:00. Now if i am trying to compare entered date with these dates i am getting literal does not match format string or date picture ends before....Can any body tell me what to do.
    Regards

    user10502390 wrote:
    hi
    i am having date from and date to feilds in my overtime element.i want to do the validation on these dates the the dates do not overlap or duplicated.the input value date from and date to are stored in database as varchar2 in the format yyyy/mm/dd 00:00:00. Now if i am trying to compare entered date with these dates i am getting literal does not match format string or date picture ends before....Can any body tell me what to do.
    RegardsPoint a) VERY BAD IDEA storing dates as VARCHAR2 on the database. It will only lead to corrupt data in the future.
    Point b) When comparing dates, you should compare them as DATE datatype as the database knows how to do comparisons against DATES. If you try and compare them as VARCHAR2 then you will most likely end up with incorrect comparisons.
    If you must have varchar2 storing of your dates/times (there's absolutely no reason to though)... you want...
    TO_DATE(:entered_date,'YYYY/MM/DD HH24:MI:SS') BETWEEN TO_DATE(DATEFROM,'YYYY/MM/DD HH24:MI:SS') AND TO_DATE(DATETO,'YYYY/MM/DD HH24:MI:SS')
    e.g.
    TO_DATE('20080815 13:23:33','YYYY/MM/DD HH24:MI:SS') BETWEEN TO_DATE(DATEFROM,'YYYY/MM/DD HH24:MI:SS') AND TO_DATE(DATETO,'YYYY/MM/DD HH24:MI:SS')

  • How to compare data between two tables?

    Hi,
    My team is trying to develop a SAP data migration tool (DMT) using ABAP.
    One of the functionalities in the DMT is to validate the data in the staging area against the loaded SAP data.
    The tables in the stagin area are customer tables (i.e. user-defined tables starting with Y, Z).
    How do I compare the data in the staging area against data that are loaded into SAP tables? Are there some built-in SAP functions to do this? Or, are there some better ways of doing this (e.g. instead of comparing against data in the SAP tables, we compare with some INTERNAL tables)?
    Any help would be greatly appreciated, thanks!

    Hi Kian,
    Use <b>SCMP</b> transaction to compare data between two tables and you can not use this for comparing internal tables.
    Thanks,
    Vinay

  • How to compare data between two worksheet in Excel for applescript

    Hi All,
    How to compare the data from two different worksheet in Excel and set the value into one worksheet according to the same name? Here is the example. Worksheet 1 & 2 current we have, the final worksheet is the result we want and the value can be input in worksheet 1. Much appreciate if you can help on it.
    Worksheet 1:
    Name          Number
    Leo                 25
    Jame               55
    Leo                 30
    Jame               60
    Tim                 44
    Tomas             77
    Lyne                35
    Tonny              66
    Jame               22
    Game              88
    Worksheet  2:
    Name          Number  2
    Leo                60
    Jame             150
    Tim                66
    Tomas            88
    Lyne               55
    Tonny            99
    Game             111
    Rusult in Worksheet 1
    Name          Number        Total Number per name in Worksheet 1         Number 2 in Worksheet 2
    Leo                 25                          55                                                        60
    Jame               55                         137                                                       150
    Leo                 30                           55                                                        60
    Jame               60                         137                                                       150
    Tim                 44                          44                                                         66
    Tomas             77                          77                                                        88
    Lyne                35                          35                                                        55
    Tonny              66                          66                                                        99
    Jame               22                         137                                                       150
    Game              88                          88                                                        111

    I'd probably use a database for this, if there's any quantity of data involved here.  Import from Excel into {SQLite, MySQL, PostgreSQL, FileMaker, maybe Core Data}, or pick your preferred key-value store, keep your data in the database, then export or (via ODBC/JDBC) then access live database data from within the spreadsheets.
    Alternatively and if you're looking at small quantities of data (say, less than 10,000 entries, or less than a thousand depending on the language), then just use whatever passes for a key-value store in your preferred scripting language {Python, bash, Lua, or maybe php, AppleScript or Java} and use that.  Export Excel to CSV {gag} or XML, then load that into Python and process as needed, then write out CSV {gag} or XML.
    AppleScript is a scripting language for GUI applications, and also useful for processing events.  If you're not doing that sort of stuff, then there can be other choices, and other choices can often have extensive frameworks and libraries for common tasks.
    Sooner or later, most everybody runs into a wall when using a spreadsheet...  Various folks have encountered those limits and have migrated from spreadsheets to FileMaker databases, and now use a database as the central store for their operations — and that's the other issue that can arise with spreadsheets... Where's the canonical data?

  • How to compare Date/time string

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

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

  • Compare date ranges in two tables

    Hello,
    I'm trying to figure out a way of comparing the range of dates between two date columns from a single row in one table, to the range of dates from multiple rows in a related table.
    t1 (t1_id, absent_start_date, absent_stop_date)
    t2 (t2_id, t1_id, cover_start_date, cover_end_date)
    t2 has multiple rows for each row in t1
    I need to select rows from t1, in which the set of days for rows in t2 do not match the set of days between absent_start_date and absent_stop_date.
    For example, assume this row in t1:
    1, '10/08/2007', '15/08/2007'
    The set of days would be 10/08/07,11/08/07,12/08/07,13/08/07,14/08/07,15/08/07
    and these rows in t2
    1, 1, '10/08/2007', '11/08/2007'
    2, 1, '12/08/2007', '12/08/2007'
    3, 1, '14/08/2007', '15/08/2007'
    The set of days would be 10/08/07,11/08/07,12/08/07,14/08/07,15/08/07
    In this case, the related rows in t2 do not cover the same date range as the master row in t1, and so I need to select this row from t1 somehow.
    Any ideas anyone?
    Thanks.

    I am not sure about the exact output you want, but the next query will give you all gaps in the periods, so the presence of a row in this output may be enough?
    SQL> create table t1
      2  as
      3  select 1 t1_id, date '2007-08-10' absent_start_date, date '2007-08-15' absent_stop_date from dual union all
      4  select 2, date '2007-09-01', date '2007-09-10' from dual
      5  /
    Tabel is aangemaakt.
    SQL> create table t2
      2  as
      3  select 1 t2_id, 1 t1_id, date '2007-08-10' cover_start_date, date '2007-08-11' cover_stop_date from dual union all
      4  select 2, 1, date '2007-08-12', date '2007-08-12' from dual union all
      5  select 3, 1, date '2007-08-14', date '2007-08-15' from dual union all
      6  select 4, 2, date '2007-09-03', date '2007-09-05' from dual union all
      7  select 5, 2, date '2007-09-07', date '2007-09-08' from dual
      8  /
    Tabel is aangemaakt.
    SQL> select  *
      2    from ( select t2.t1_id
      3                , lag(t2.end_date+1,1,t1.absent_start_date) over (partition by t2.t1_id order by t2.start_date) gap_start_date
      4                , t2.start_date-1 gap_end_date
      5             from t1
      6                , ( select t1_id
      7                         , cover_start_date start_date
      8                         , cover_stop_date end_date
      9                      from t2
    10                     union all
    11                    select t1_id
    12                         , absent_stop_date+1
    13                         , absent_stop_date+1
    14                      from t1
    15                  ) t2
    16            where t1.t1_id = t2.t1_id
    17         )
    18   where gap_start_date <= gap_end_date
    19   order by t1_id
    20       , gap_start_date
    21  /
                                     T1_ID GAP_START_DATE      GAP_END_DATE
                                         1 13-08-2007 00:00:00 13-08-2007 00:00:00
                                         2 01-09-2007 00:00:00 02-09-2007 00:00:00
                                         2 06-09-2007 00:00:00 06-09-2007 00:00:00
                                         2 09-09-2007 00:00:00 10-09-2007 00:00:00
    4 rijen zijn geselecteerd.Regards,
    Rob.

  • How to compare data from 2 different time periods

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

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

  • How to limit data range in a Line chart with Time Refresh Control

    Hi All,
    I have a Line chart with Time Refresh Control and I would like to make some constraints to this navigation.
    For example, I would like to limit the user to navigate in a data range of 8 hours.
    Is this posible?
    Thanks in advance

    Hi Pedro,
    as far as I know, this is not possible using the time controls on an iChart. However, you may have some success by using your own time controls which call JavaScript methods exposed by the applet.
    For example, you could begin by hiding the time and calendar buttons on an iChart, and creating some buttons of your own. For instance, to set the start date of a query (and thus the start date of the iChart using the query), you can use the following:
    document.getElementById("appletID").getQueryObject().setStartDate(<date string>);
    Using code like the above (look into the xMII script assistant and documentation), you should be able to build time controls which satisfy your requirements. The exact format of <date string> in the sample above will depend on the date format defined in the query template this script calls.
    Hope this helps,
    Sascha

  • How to pass date range as filter in Go URL

    Hi,
    I am trying to construct a Go Url which has two filters, date range & text. I have constructed the url as below but it keeps throwing an error. The url is not passing the max date and the application is throwing following error:
    Error: State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 46048] Datetime Month value 0 from 0000-00-00 is out of range. (HY000)
    Go Url: https:companyUrl?Go&Options=rfd&Path=/shared/CompanyID/Reportlink&P0=2&P1=eq&P2=CustomObject4.%22Indexed%20Pick%201%22&P3=Leasing&P4=bet&P5="- CustomObject4 Custom Attributes".ZDate_26&P6=2+Date%20'2014-08-01'+Date%20'2014-12-31'
    Please suggest.
    Thanks,
    Kiran.

    Looks like you are converting the datatype from char to date in URL, I dont think this can be done.
    Your code is like
    &P6=2+Date%20'2014-08-01'+Date%20'2014-12-31'
    It suppose to be &P6=2+2014-08-01+2014-12-31
    I would suggest to do the formatting for this filed using Column properties and try.
    Hope this helps, pls mark if it does ;)

Maybe you are looking for

  • Get selected values from checkbox group

    Hi, I am working a jsf project on NetBeans 6 with the woodstock project and I want to save in a list or an array or something, the ids of the checkboxes that are selected into a checkboxgroup.Could someone explain to me the process of this?I am a new

  • KO88 Internal Order Error  KD256

    Hi All, When I am excuting settlement of a order thru KO88 it gives the massage as under: There are no accrued amount; settlement is not possible Massage KD256 When I checked the cost analysis of the particular order it has some cost in the particula

  • Getting ClassCastException when accessing Blob object

    I am using weblogic 5.1 with service pack 10. I need to query pdf data stored in a blob field in Oracle 8.1.6 server. The native code c:\weblogic\bin\oci816_8 is part of the path. When I query the database with Oracle 8 client, I can get data. driver

  • Spotlight Unresponsive?

    Hey all, It appears to me that Spotlight has been disabled. When I use my Spotlight hotkey (the default), the blue magnifying glass doesn't pop up with a search box, neither does Command + Alt + Space, which should be the bigger Spotlight window. I'v

  • What firefox works with snow leopard for mac?

    I upgraded my Mac tower and Macbook pro to snow leopard 10.6.8. What version of firefox should I be downloading? I am running Firefox 21. Thanks for your help!