Compare date with timestamp

I have data in timestamp format like 10/06/2009 11:59:01 PM EDT. I need to compare it with sysdate after removing the PM EDT etc.
I tried to_date, trunc etc... nothing worked. Is there a way to remove that PM EDT and compare with sysdate.

Hi,
What problem you face when you directly compare timestamp column with sysdate?
select cast (systimestamp as timestamp with local time zone) -sysdate from dual;
CAST(SYSTIMESTAMPASTIMESTAMPWITHLOCALTIMEZONE)-SYSDATE
+000000000 00:00:00.481609Regards
Anurag Tibrewal.

Similar Messages

  • Performance question when compare date with date or char with char

    Hello from Germany (Frankfurt) !
    I am working on Oracle 9.2.0.8.0
    and have to solve following problem:
    Comparison of a date and char fields.
    Now two ways to do it.
    Either I compare char with char and convert date to char,
    or I compare date with date and convert char to date.
    Now the performace question. Which operation takes more effort for the database?
    So why not to try and to see the results?
    First create table:
    CREATE TABLE TEST (
    char_date VARCHAR2(8),
    real_date DATE
    NOLOGGING;
    Then insert 1.000.000 rows
    BEGIN
    for x in 1..1000000
    loop
    insert into test (char_date, real_date) VALUES('19990101', TO_DATE('2006.01.01', 'YYYY.MM.DD'));
    end loop;
    COMMIT;
    END;
    Collect statistics
    EXEC dbms_stats.gather_table_stats('TESTER', 'TEST');
    Now run some selects for date to char conversion:
    Elapsed: 00:00:00.00
    SQL> select * from test t where TO_DATE(char_date, 'YYYYMMDD') > real_date;
    no rows selected
    Elapsed: 00:00:03.02
    SQL> select * from test t where TO_DATE(char_date, 'YYYYMMDD') > real_date;
    no rows selected
    And some selects for char to date conversion:
    Elapsed: 00:00:03.02
    SQL> select * from test t where char_date > TO_CHAR(real_date, 'YYYYMMDD');
    no rows selected
    Elapsed: 00:00:02.05
    SQL> select * from test t where char_date > TO_CHAR(real_date, 'YYYYMMDD');
    no rows selected
    Elapsed: 00:00:02.05
    SQL>
    As you see when I compare char with char and convert date to char it seems to be faster (almost 1 second)
    Is the test correct?
    I still not sure, what gets better performance...
    Any idea?
    Thanks!

    Depends on whether you want the right results or not.
    Why don't you run the following two queries and see if the difference in results tells you anything?:
    with t as (select to_date('01/02/2007', 'dd/mm/yyyy') date_col from dual
               union all
               select to_date('02/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/03/2006', 'dd/mm/yyyy') from dual)
    select *
    from   t
    where  date_col < to_date('04/03/2006', 'dd/mm/yyyy');
    with t as (select to_date('01/02/2007', 'dd/mm/yyyy') date_col from dual
               union all
               select to_date('02/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/03/2006', 'dd/mm/yyyy') from dual)
    select *
    from   t
    where  to_char(date_col) < '04/03/2006';

  • Deleting records based on date with timestamp

    Hi there,
    In continuation from my earlier Query. Multiple reccord have inadvertantly been inserted in the LOAN_TXN table. I want to delete all the records, except one, based on date with timestamp.
    CREATE TABLE LOAN_TXN
    TXN_DATE                     DATE,
    BALANCE          NUMBER(10,2),
    CODE          VARCHAR2(1),
    INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '02/15/2010 11:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), 250000, 'D');
    INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '03/31/2010 11:59:59 AM', 'MM/DD/YYYY HH:MI:SS AM'), 250000, 'B');
    INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '05/14/2010 11:25:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), 500000, 'D');
    INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '06/30/2010 12:15:00 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
    INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '08/02/2010 10:45:26 AM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
    INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '09/08/2010 02:10:17 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
    INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '10/27/2010 04:25:20 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
    INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '11/09/2010 10:15:55 AM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
    INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '12/29/2010 03:10:20 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
    INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '01/12/2011 01:11:15 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
    INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '02/11/2011 12:11:48 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
    INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '03/31/2011 11:59:59 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
    INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '03/31/2011 11:59:59 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
    INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '03/31/2011 11:59:59 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
    INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '03/31/2011 11:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
    INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '03/31/2011 11:59:59 AM', 'MM/DD/YYYY HH:MI:SS AM'), 460000, 'B');I want to delete mutiple records, except one, with code 'R' and TXN_DATE = '03/31/2011 11:59:59 PM' How do I do that ?

    user3308033 wrote:
    I think your query would delete all the duplicate records. Keeping one, I just want to delete mutiple records with timestamp : 11:59:59.
    DELETE FROM loan_txn
    WHERE rowid != (
                     SELECT  MIN(rowid)
                       FROM  loan_txn
                       WHERE txn_date = TO_DATE('03/31/2011 11:59:59 PM','MM/DD/YYYY HH:MI:SS AM')
                         AND code = 'R'
        AND txn_date = TO_DATE('03/31/2011 11:59:59 PM','MM/DD/YYYY HH:MI:SS AM')
        AND code = 'R'
    /SY.

  • Compare date with time

    Hi ,
    Oracle 10.2.0.1.0
    I need to compare date field with time stamp as well . I tried doing byt getting time stamp using to_char and on convertion into date by using to_date , I'm loosing time stamp please help

    804282 wrote:
    I need to compare date field with time stamp as well Compare how exactly?
    If you for example want to see if the date and timestamp are "equal", you can use the following approach - where in this specific approach it is deemed that if the difference between the timestamp and date is less than 1 sec, the two values are equal. E.g.
    SQL>
    SQL> create table test_tab(
      2          d       date,
      3          t       timestamp
      4  );
    Table created.
    SQL>
    SQL> insert into test_tab values( sysdate, systimestamp );
    1 row created.
    SQL> --// is the date and timestamp within 1 sec of one another?
    SQL> select * from test_tab where t-d <  to_dsinterval('0 0:0:1.00');
    D                   T
    2011/07/12 07:25:06 12/JUL/11 07:25:06.744832
    SQL> --// the reverse test
    SQL> select * from test_tab where t-d >=  to_dsinterval('0 0:0:1.00');
    no rows selected
    SQL>

  • 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')

  • SQL Developer 3.2 - Exporting data with TIMESTAMP datatype

    Hi,
    We have users that are attempting to export data with the Timestamp format to Excel (xls format) using SQL Developer 3.2.  When attempting to sort the Timestamp in either asc or desc order, Excel is having issues sorting correctly.  I suggested that the user just do all the sorting within their SQL Developer session but they require the ability to slice and dice in Excel.
    This is definitely not an issue with Excel as the users have previously exported Timestamp data from Toad and been able to sort without issue.  Any thoughts as to what might resolve this issue? 
    Thanks.

    We're not formatting timestamps in Oracle as numbers/dates in Excel. They'll need to properly format the Excel column/cells to get it to sort the way they want vs being treated as simple strings.

  • Compare Date with Timezone

    Hi,
    I have a Date which is stored in the Database with the timezone like GMT, I have a java.util.Date which is selected in my UI from a Customized Calendar, I am converting this Date with timezone and want to compare this date with the date with timezone stored in the DB? How to accomplish this, please shed some light into this?
    Thanks.

    797836 wrote:
    I have a Date which is stored in the Database with the timezone like GMT, I have a java.util.Date which is selected in my UI from a Customized Calendar, I am converting this Date with timezone and want to compare this date with the date with timezone stored in the DB?As Parul said, Date does not involve a timezone. I think you need to clarify what you mean by "I am converting this Date with timezone", because it doesn't make much sense to me.
    BTW: If the date in your database is a standard SQL Date, then it will be converted to a java.sql.Date when you read it into Java with JDBC. And java.sql.Date is directly comparable with java.util.Date (in fact, it's a subclass).
    Winston

  • How to insert date with timestamp into table values

    hi,
    I have a table
    create table abc1(dob date);
    insert into abc1 values (to_date(sysdate,'RRRR/MM/DD HH24:MI:SS'))
    but when i see in data base it shows as normal date without time stamp.
    Is it possible to insert into back end with timestamp.
    Thanks..

    First, SYSDATE is a DATE already, no need to convert it to a DATE using the TO_DATE() function.
    The date ALWAYS has a time component, whether or not it is displayed is up to your NLS settings. for example:
    SQL> CREATE TABLE ABC1(DOB DATE);
    Table created.
    SQL> ALTER SESSION SET NLS_DATE_FORMAT='MM/DD/YYYY';
    Session altered.
    SQL> INSERT INTO ABC1 VALUES(SYSDATE);
    1 row created.
    SQL> SELECT * FROM ABC1;
    DOB
    02/04/2010
    SQL> ALTER SESSION SET NLS_DATE_FORMAT='MM/DD/YYYY HH24:MI:SS';
    Session altered.
    SQL> SELECT * FROM ABC1;
    DOB
    02/04/2010 12:54:57
    SQL> DROP TABLE ABC1;
    Table dropped.

  • How to compare date with null value

    Hi
    I have a date filed and i assigned that input box with context attribute of type Date.
    Here my problem is
    when the end user not entered any thing (null ) the i have give some defaul date.
    so first in the action method i have to check the date with null
    if it is null i have to give default date.
    so please let me know how to over come this.
    thanks
    Mukesh

    Hi
    You can get your date in your action method like
    Date newDate=new Date();
    Date myDate= wdThis
                              .wdGetYourComponentNameController()
                                      .wdGetContext()
                                           .currentYourNodeNameElement()
                                                           .getYourDateName();
    if ( myDate== null) {
             wdContext.currentContextElement().setYourDateName(newDate);
    else{...........//continue your other validations or calling other methods}
    Regards
    Abhijith YS
    Message was edited by:
            Abhijith YS

  • Logic to compare date with standard timestamp

    Hi Experts,
    I want to retrieve the data which is "n" moths old.
    To compare that I want use only SYSDATE without timestamp.
    I want to use standard timestamp '23:59:59' along with SYSDATE.
    The condition should be as below.
    UPDATE_DATE <= ADD_MONTHS(15/01/2013 23:59:59,-3)
    UPDATE_DATE <= ADD_MOTHS(30/01/2013 23:59:59,-4)
    UPDATE_DATE<=ADD_MONTHS(sysdate||' '||'23:59:59',-3);Please help me how to implement it.
    Thanks in advance.

    973205 wrote:
    Thanks for your reply.
    Your query is not meeting my requirement.
    It just adding one day after it's adding months.
    TRUNC(sysdate) means it will truncate timestamp.
    I want to use standard timestamp along with sysdate.
    TRUNC(sysdate)||' '||'23:59:59' after that I want to add months.
    What you are trying to do is to concatenate a character string to a DATE value - which will not work and is not logical also..
    This can be achieved as below - minus 1 second from trunc(sysdate+1)
    select trunc(sysdate+1)-(1/(24*60*60)) dt
    from dual;
    DT                  
    03-Feb-2013 23:59:59   Your requirement is to filter as UPDATE_DATE<=ADD_MONTHS(sysdate||' '||'23:59:59',-3);
    This can be done as
    UPDATE_DATE<=ADD_MONTHS(trunc(sysdate+1)-(1/(24*60*60)),-3);The same thing can be achieved by replacing "<=" with "<" as
    UPDATE_DATE<ADD_MONTHS(trunc(sysdate+1),-3);Edited by: jeneesh on Feb 3, 2013 12:39 PM

  • To compare date with another date in string in siebel bip report

    Hi,
    In my rtf I am comparing a Date1 with a date in string i.e. '10-NOV-14'. If Date1 is less than '10-NOV-14' I am dispalying a certain text and if not another text.
    This condition is working fine if Date1 have 2014 values but if  Date1 cointains 2015 date than the mentioned condition is falling.
    Kindly suggest any solutions.
    Regards,
    Siddhika

    This example may help:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:param name="currentDate"/>
        <xsl:variable name="firstDate" select="concat(substring($currentDate, 1,4),substring($currentDate, 6,2),substring($currentDate, 9,2))"/>
        <xsl:template match="/">
            <xsl:apply-templates select="//item"/>
        </xsl:template>
        <xsl:template match="item">
            <xsl:variable name="secondDate" select="concat(substring(submissionDeadline, 1,4),substring(submissionDeadline, 6,2),substring(submissionDeadline, 9,2))"/>
            <xsl:choose>
            <xsl:when test="$firstDate &gt; $secondDate">
                <xsl:call-template name="late"/>
                </xsl:when>
                <xsl:when test="$firstDate &lt; $secondDate">
                    <xsl:call-template name="ontime"/>
                </xsl:when>
                <xsl:when test="$firstDate = $secondDate">
                    <xsl:call-template name="same"/>
                </xsl:when>
                <xsl:otherwise>Monkeys<br /></xsl:otherwise>
            </xsl:choose>
        </xsl:template>
        <xsl:template name="ontime">
            This is on time
        </xsl:template>
        <xsl:template name="late">
            This is late
        </xsl:template>
        <xsl:template name="same">
            This is on time
        </xsl:template>
    </xsl:stylesheet>

  • How to Compare date with Current system date in XSLT mapping.

    Hello Experts
    In a XSLT mapping program, I hava a filed, ZZOB which is giving some date.
    which I need to compare with the current date.
    Condition-
    ZZOB is greater than current date or ZZOBLIG = NULL
    Then go further statements.
    how can i campare with the current date?
    Please help.
    Thanks
    Balaprasad

    This example may help:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:param name="currentDate"/>
        <xsl:variable name="firstDate" select="concat(substring($currentDate, 1,4),substring($currentDate, 6,2),substring($currentDate, 9,2))"/>
        <xsl:template match="/">
            <xsl:apply-templates select="//item"/>
        </xsl:template>
        <xsl:template match="item">
            <xsl:variable name="secondDate" select="concat(substring(submissionDeadline, 1,4),substring(submissionDeadline, 6,2),substring(submissionDeadline, 9,2))"/>
            <xsl:choose>
            <xsl:when test="$firstDate &gt; $secondDate">
                <xsl:call-template name="late"/>
                </xsl:when>
                <xsl:when test="$firstDate &lt; $secondDate">
                    <xsl:call-template name="ontime"/>
                </xsl:when>
                <xsl:when test="$firstDate = $secondDate">
                    <xsl:call-template name="same"/>
                </xsl:when>
                <xsl:otherwise>Monkeys<br /></xsl:otherwise>
            </xsl:choose>
        </xsl:template>
        <xsl:template name="ontime">
            This is on time
        </xsl:template>
        <xsl:template name="late">
            This is late
        </xsl:template>
        <xsl:template name="same">
            This is on time
        </xsl:template>
    </xsl:stylesheet>

  • How to compare date with thr current date

    Hi,
    I have an inout string which is in date format(dd/mm/yyyy hh:mm:ss) .
    what i need to do is comparing this date string with the current date. if my input string is less than current date , then display error message..
    how to do this?
    regards

    Excellent suggestions from all of you people!
    finally i got the solution
    code is:
    import java.util.*;
    import java.text.*;
    public class TestDate {
      public static void main(String args[]){
        TestDate a = new TestDate();
      TestDate() {
        String DATE_FORMAT = "dd/MM/yyyy hh:mm:ss";
         Date today = new Date();
         Date myDate=null;
        java.text.SimpleDateFormat sdf =
             new java.text.SimpleDateFormat(DATE_FORMAT);
         try{
         myDate = sdf.parse("01/06/2006 00:00:00");
         }catch(Exception e) {System.out.println(e);}
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();
        c1.setTime(today);
        c2.setTime(myDate1);
        System.out.print(sdf.format(today));
        System.out.print(sdf.format(c1.getTime()));
        if (c1.before(c2)) {
           System.out.print(" is before ");
        if (c1.after(c2)) {
           System.out.print(" is after ");    
        if (c1.equals(c2)) {
           System.out.print(" same as ");    
    System.out.print(sdf.format(c2.getTime()));
      }

  • Compare date with implements Comparator

    I have a DefaultListModel (mode) staffed with EMPL (id, name, startingDate). I would like to sort the defaultListModel accourding to the dob. for this I do the following:
                   Object[] contents = model.toArray();               
                   Arrays.sort(contents, new ComparatorDate());
                   model.copyInto(contents);the comparator: ComparatorDate
    public class ComparatorDate implements Comparator
         public int compare(Object o1, Object o2)
              Empl a = (Empl ) o1;
              Empl b = (Empl ) o2;
              Date d1 = a.getStartDate();
              Date d2 = b.getStartDate();
              return (d1.getDate()-d2.getDate());
    }when debugging I realize the dates are diff but the d1.getDate()=1 and d2.getDate()=1 ??? how come? the result are not what expected.
    any idea?

    getDate() tells you the day of the month. Both your dates are apparently on the first of some month. Since Date implements Comparable, why not just do return d1.compareTo(d2)

  • SQL: comparing date with datetime field

    I'm having a brain fart as I assume this is really simple.
    Given that I have the date in the format of yyyy/mm/dd, how
    do I put that
    into a sql query that compares that to the datetime field?
    It appears the datetime field, by default, uses this format:
    m/d/yyyy
    hh:mm:ss am
    -Darrel

    If your date formats are different you will have to use CAST
    or CONVERT
    functions as you state you already have. If this works then
    stick with it.
    You may also need to use a SET DATEFORMAT command. See below:
    http://msdn2.microsoft.com/en-us/library/ms189491.aspx
    Dates in SQL Server can be a bit of a pain to work with. It
    is usually best
    practice to store your DateTime data in raw format and use
    CAST or CONVERT
    functions in your Stored Procs to get the correct results.
    Pat.
    "darrel" <[email protected]> wrote in message
    news:ftloim$jv4$[email protected]..
    >
    >> What dbms?
    >
    > t-sql (MSSQL)
    >
    > For now, via string functions, I rearrange the date/time
    format manually,
    > and then use the CAST statement in the SQL query. Not
    pretty, but seems to
    > work.
    >
    > -Darrel
    >

Maybe you are looking for

  • Performance issues with FDK in large XML documents

    In my current project with FrameMaker 8 I'm experiencing severe performance issues with some FDK API calls. The documents are about 3-8 MBytes in size. Fortmatted they cover 150-250 pages. When importing such an XML document I do some extensive "post

  • Single Sing On in PI 7.0

    Dear All, Could you please provide me help on this,how to create SSO in PI 7.0.? Thanks & Regards, Venkat.

  • How to get adobe-livecycle-reader-extensions

    How (where) can i get LiveCycle-ReaderExtensions for to make AdobeReader able to connect to a Database (example "Excel-Sheets) Costs? Thanks a lot for your help! Regards Firefox2013

  • Plz help me if someone can

    Just few days back on my iPhone it was showing the correct place in my current location but it's showing unknown location. I checked every thing that whether my local localizations is on or not and I switched off n on my phone many time but it didn't

  • How do i uninstall flash player and get lightspark to take its place?

    how do i uninstall flashplayer and get lightspaerk to take its place?