Compare two dates in different format.

Hi
I want to compare two dates....one of which is in the timeStamp format ("yyyy-MM-dd HH:mm:ss")
and the other is in java.util.Date i.e Tue Oct 11 10:22:47 GMT+05:30 2005
Do I have to tokenise and then compare them.Is there any better approach?
I want to find out which is greater/smaller one.
Pls help.
Regards,
Sandip.

I would convert both to Date and compare them. To convert String to Date check java.text.SimpleDateFormat and its parse(...) method.
HTH
Mike

Similar Messages

  • Comparing two numbers with different formats

    Dear Java developers
    I am trying to compare two numbers but they have different formats. long x = 8981261369, Object obj = "8,981,261,369".
    I am trying to see if this two values are equal which is the case in the example above except one has a thousand separator but not sure how to do that.
    How can I lose the thousand separator and just compare them as two long values.
    Your input will be much appreciated
    Thanks

    iu433 wrote:
    I need a generic way of doing this. Because sometimes the Object does not have a thousand separator. Can i use some kind of NumberFormat to do this.You'll need to know what formats the string (not the number--as already mentioned, numbers don't have formats) can have, and then try them one by one.
    Of course, there can be some ambiguity. Does "123,456" represent one hundred twenty three thousand four hundred fifty six, or is that comma a decimal separator, and it represents one hundred twenty three and four hundred fifty six thousandths?
    The point is, you have to have a clear definition of what formats are allowed and how to determine which one it is. There's no magic way for Java to do that for you.

  • Date in different formats

    Hello All,
    I have requirement in SAP script where I need to compare the system date and condition validity date and display the value if todays date lies in validity date. What is the best way to do this , I have tried using a perform statment but the date when being passed into the program is appearing in different formats in dev server (dd.mm.yyyy) and test servers(yyyy.mm.dd), I have checked the user settings and they are similar why is the date being passed in different formats.
    Thanks in advance,
    ranjan

    Hi Ranjan,
    or if you want to compare two dates.
    use the FM "CONVERT_DATE_TO_INTERNAL " it converts user setting date to internal format YYYYMMDD
    then you can compare
    USe the FM "CONVERT_DATE_TO_EXTERNAL "  it converts the input date to user setting format it is (dd.mm.yyyy) and test servers(yyyy.mm.dd),
    data : formatted_date(10).
    WRITE sy-datum  TO formatted_date MMDDYYYY.
    Now for all users the date format will appear MMDDYYYY regardless to user setting.
    Prabhudas

  • Comparing two dates and adding days to date

    Hi,
    I want to compare two dates(like 2006/10/21 and 2006/11/2),how can i compare these two dates,like which is greater.And if to the second date,i want to add some number of days like 10 days,how can i add so that the date becomes 2006/11/12).
    Please reply soon.Thanks

    No,all other queries are different,as they have the
    date in this format
    '2006-03-06 " but i have the date in this format
    "2006-03-06 10:26:46.0",
    i.e the time is also assciated with it.
    If I have only the date(in string format or date
    date format 2000/12/1),then I can easily do it,but
    I have the time also.If I have the date only,then I
    can split the date into three strings,and after
    converting into integer I can pass it to the
    constructor,but what about the time?SimpleDateFormat can parse "2006-03-06 10:26:46.0" date too:
               SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SS");
               Date date = dateFormat.parse("2006-03-06 10:26:46.0");
               System.out.println("date = "  +date);

  • Comparing two dates in a report

    Hello,
    I am attempting to compare two dates in a report in order to format a column. My code for that portion of the report is as follows:
    CASE
       WHEN TO_DATE(DATE_DUE,'DD-MON-YYYY') -
            TO_DATE(sysdate,'DD-MON-YYYY') <= 5 THEN
              '<span class="due">'||DATE_DUE||'</span>'
       ELSE
          DATE_DUE
    END AS DATE_DUE,I'm getting the error message ORA-00932: inconsistent datatypes: expected CHAR got DATE.
    I've been trying to fix the condition to get rid of the error with no success.
    Thanks
    -Brian

    One thing I just noticed that may or may not be the problem is that your case statement is returning two different datatypes depending on the condition. In one part, it is returning a character string of the span tags concatenated with the due_date (which in and of itself are incompatible datatypes) and the second part is returning just a date.
    Again, not sure if the SQL engine will do automatic conversions for you, but this seems to jive with your "char vs. date" error.

  • Compare two dates in a report

    Hi,
    I would like to compare two dates on a report.
    I would like to compare the opportunity created date and the opportunity modified date. I can't use this formula CASE WHEN Opportunity."Last Modified" = Opportunity."Created Date" then 1 else 0
    I think I have to use TIMESTAMPDIFF but I don't know which interval I have to put to analyze the entire date in this format 31/12/1999 16:49:08
    Thanks a lot for your help
    Regards,

    Hi !
    It depends on the interval you need to compare these dates. If you want to know the number of days between these dates, you'll have to use SQL_TSI_DAY as interval. If it's minutes, you'll need SQL_TSI_MINUTE...
    Here are the possible intervals :
    *SQL_TSI_SECOND, SQL_TSI_MINUTE, SQL_TSI_HOUR, SQL_TSI_DAY, SQL_TSI_WEEK, SQL_TSI_MONTH, SQL_TSI_QUARTER, or
    SQL_TSI_YEAR*
    Hope this will help, feel free to ask more !
    Max

  • How to compare two database on different servers

    hi,
    I want to compare two database on different servers in oracle.first i want to ckechk thier structures and then data.i m using oracle 10.2.0.plz help me out
    Thanks in advance

    In terms of structures, there are various tools out there that can do this, such as TOAD which can do a database compare.
    In terms of data comparisons, that will depend on what sort of results you are expecting to see. I'm sure some tools will do it for you, but it can be just as easy to write your own comparison using a database link from one database to the other.

  • Compare two string in different line in textarea

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TextCounterPanel extends JPanel {
    private JTextArea textInput;
    private JLabel lineCountLabel;
                        public TextCounterPanel() {
                        setBackground(Color.DARK_GRAY);
                        textInput = new JTextArea();
                        textInput.setBackground(Color.WHITE);
                        JPanel south = new JPanel();
                        south.setBackground(Color.DARK_GRAY);
                        south.setLayout( new GridLayout(4,1,2,2) );
                             JButton countButton = new JButton("Process the Text");
                             countButton.addActionListener( new ActionListener() {
                                  public void actionPerformed(ActionEvent evt) {
                                       processInput();
                             south.add(countButton);
                        lineCountLabel = new JLabel(" Number of lines:");
                        lineCountLabel.setBackground(Color.WHITE);
                        lineCountLabel.setForeground(Color.BLUE);
                        lineCountLabel.setOpaque(true);
                        south.add(lineCountLabel);
                        setLayout( new BorderLayout(2,2) );
                        setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
                        JScrollPane scroller = new JScrollPane( textInput );
                        add(scroller, BorderLayout.CENTER);
                        add(south, BorderLayout.SOUTH);
    public void processInput() {
    String text,vin; // The user's input from the text area.
    text = textInput.getText();
    vin =text.substring(25,42);
    lineCountLabel.setText(" vin: " + vin);
    } // end class TextCounterPanel
    How can I compare two string in different line in text area

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TextCounterPanel extends JPanel {
    private JTextArea textInput;
    private JLabel lineCountLabel;
    public TextCounterPanel() {
    setBackground(Color.DARK_GRAY);
    textInput = new JTextArea();
    textInput.setBackground(Color.WHITE);
    JPanel south = new JPanel();
    south.setBackground(Color.DARK_GRAY);
    south.setLayout( new GridLayout(4,1,2,2) );
    JButton countButton = new JButton("Process the Text");
    countButton.addActionListener( new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    processInput();
    south.add(countButton);
    lineCountLabel = new JLabel(" Number of lines:");
    lineCountLabel.setBackground(Color.WHITE);
    lineCountLabel.setForeground(Color.BLUE);
    lineCountLabel.setOpaque(true);
    south.add(lineCountLabel);
    setLayout( new BorderLayout(2,2) );
    setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
    JScrollPane scroller = new JScrollPane( textInput );
    add(scroller, BorderLayout.CENTER);
    add(south, BorderLayout.SOUTH);
    public void processInput() {
    String text,vin; // The user's input from the text area.
    text = textInput.getText();
    vin =text.substring(25,42);
    lineCountLabel.setText(" vin: " + vin);
    } // end class TextCounterPanel

  • How to Compare two Dates in java

    How to Compare two Date Field after getting the values from jTextField1.getText() and jTextField2.getText().

    Date d1=DateFormat.getDateInstance().parse(yourstring1);
    same for d2
    d1.compareTo(d2);
    could be that i misrememberd the exact naems of some functions or mixed up something in the equence of d1=

  • Comparing two data records of same IDOC

    Hi,
    In PI, we need to compare two data records of same IDOC to figure out if what type change occurred.  For example, BENFIT3 IDOC contains data records tilted "E1BEN04".  When there are multiple "E1BEN04" data records, then we need to compare the data inside them to see whether name, or data of birth or SSN is changed. 
    Has anybody came across this before. Your help is much appreciated.
    Thanks
    -Teja

    If it is very few fields then you could use graphical mapping to determine the changes.

  • Compare Two Date - Very Urgent

    hi to all,
    i want to compare two date..
    i m getting one date from database and having current date..
    what my issue is i want to dispaly error message when database date greater
    than current date value..
    pls help to my problem...

    import java.util.*;
    public class DateVlid {
         public static void main(String[] args)throws ParseException {
              Calendar currentDate=Calendar.getInstance();
              Calendar dbDate=Calendar.getInstance();
              dbDate.set(2007,12,10);
              boolean b=currentDate.before(dbDate);
              if(b){
                   System.out.println("it is before date");
    }Try it once for a while.
    If it has any problems let me know.

  • Java 1.3 comparing two dates using Calendar.before(Calendar)

    Has anyone used the Calendar.before() method for comparing two dates, how accurate is this?
    Some users have found problem with this method, is this true?

    manjit84 wrote:
    Has anyone used the Calendar.before() method for comparing two dates, Yes.
    how accurate is this?I've never noticed a problem.
    Some users have found problem with this method, is this true?Check the bug database^1^?
    ^1^ http://bugs.sun.com/

  • How to compare two dates that should not exceed morethan 3 years

    hi all,
    can you please tell me how to compare two dates( basically dates are string type)
    that should not exceed more than 3 years? in JAVASCRIPT
    Thanks in Advance.

    This is not a JavaScript forum.
    [*Google* JavaScript Forum|http://www.google.co.uk/search?q=JavaScript+Forum&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a]
    Good luck.

  • How to compare two dates to know which one is greater than oher?

    how to compare two dates to know which one is greater than oher?
    Please search before asking basic questions.
    Edited by: Rob Burbank on Mar 27, 2009 9:26 AM

    Hi,
    If thse to date fields are of same type u can directly compare like this.
    regards,
    Bharat.

  • Compare two dates with NULL in one

    I am trying to do the following with a simple SQL. Compare two dates and get the latest one, but the greatest() function always returns NULL if NULL is present. So how can I do it ?
    Date1 Date2 Desired Result
    Null 01-Dec-09 01-Dec-09
    01-May-09 01-Mar-09 01-May-09
    01-May-09 NULL 01-May-09
    01-May-09 01-Nov-09 01-Nov-09
    NULL NULL NULL
    Any suggestion ? Thanks

    Hi,
    Try this,
    create table test1
    fdate date,
    tdate date
    insert into test1 values (null,'25-jan-2010');
    select greatest(nvl(fdate,tdate),nvl(tdate,fdate)) greatest from test1;
    Thanks&Regards,
    Jai

Maybe you are looking for

  • Mac-mini "detect displays" where is the individual model's DDC info stored?

    I have a dilemna- I just bought a new 20" NEC LCD screen that has all sorts of bells and whistles. It's 1600 x 1050 native, and has DVI, analog VGA, YUV, compostie, and RF inputs. It is supposed to have a scalar that supports a multitude of resolutio

  • Lightroom wont open. Says unexpected error opening catalogue.

    Please advise.

  • IN Clause in Report

    Hi, I want to give mutiple parameters in report e.g. my query is select * from dept where departname in (Mutiple Values). When the report will run, user can enter either one OR mutiple departments.... Thanks John

  • Updating nokia3110c with nokia software updater - ...

    I tried to update my nokia3110c with nokia software updater but failed every time. I think it is because of poor quality of my internet connection. My network provider doesn't support the update using phone . Is their any other way to download an ins

  • Report on Asset,SQl script

    Hi Friends, There is a urgent requirement in our project related to SQL queries. I don't have much knowledge on SQL/script. Need to write an script with the following requirements(asset.no,description,P.O no,location,person_in_charge). Please can any