Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: How to compare a date to sysdate

Re: How to compare a date to sysdate

From: Arjan van Bentem <avbentem_at_DONT-YOU-DAREdds.nl>
Date: Tue, 2 Mar 1999 23:05:53 +0100
Message-ID: <36dc60c8$0$10429@pascal>


ramdan wrote
>SQL> SELECT SYSDATE FROM DUAL;
An Oracle data always includes the time as well.

As you do not specify a print format, Oracle prints it using the default format which happend to be dd-mon-yyyy in your case. However, printing is only done in the very final stage of your query. In the where clause, the dates still have the time part, and you would be very lucky to have an exact match.

    select to_char(sysdate, 'dd-Mon-yyyy hh24:mi:ss')     , to_char( trunc(sysdate), 'dd-Mon-yyyy hh24:mi:ss')     from dual;

>select * from tab1row
>where readdate = (select sysdate from dual);

Like shown above, use trunc(my_date) to set the time part to midnight, 0:00:00

    select *
    from tab1row

    where trunc(readdate) = trunc(sysdate);

Note that no subquery is needed to use sysdate.

Arjan. Received on Tue Mar 02 1999 - 16:05:53 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US