Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Date comparison question
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C079AE.252DC1C0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
> -----Original Message-----
> From: Lisa Yates [mailto:cosnit_at_creighton.edu]
> Sent: lundi, 8. janvier 2001 11:27
>
> Why doesn't this query ever return...
>=20
> where run_date =3D to_date('01-03-2001 16:34:59','mm-dd-yyyy=20
> hh24:mi:ss')
>=20
> but this query does....
>=20
> where to_char(run_date) =3D to_char(to_date('01-03-2001
> 16:34:59','mm-dd-yyyy hh24:mi:ss'))
>=20
> and so does this query....
>=20
> where to_char(run_date,'mm-dd-yyyy hh24:mi:ss') =3D '01-03-2001=20
> 16:34:59'
I was able to duplicate your results by inserting a row in a table with =
a
"negative" date (aka a "BCE" date).
SQL> create table t (d date) ;
Table created.
SQL> insert into t (d) values (to_date ('-2001/01/03 16:34:59', =
'SYYYY/MM/DD
HH24:MI:SS')) ;
1 row created.
SQL> select count (*)
2 from t
3 where d =3D to_date('01-03-2001 16:34:59','mm-dd-yyyy hh24:mi:ss') =
;
COUNT(*)
0
SQL> select count (*)
2 from t
3 where to_char(d) =3D to_char(to_date('01-03-2001 =
16:34:59','mm-dd-yyyy
hh24:mi:ss'))
4 ;
COUNT(*)
1
SQL> select count (*)
2 from t
3 where to_char(d,'mm-dd-yyyy hh24:mi:ss') =3D '01-03-2001 16:34:59' =
;
COUNT(*)
1
select count (*)
from t
where d =3D to_date('01-03-2001 16:34:59','mm-dd-yyyy hh24:mi:ss') ;
Jacques R. Kilcho=EBr
(949) 754-8816
Quest Software, Inc.
8001 Irvine Center Drive
Irvine, California 92618
U.S.A.
http://www.quest.com=20
------_=_NextPart_001_01C079AE.252DC1C0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML> <HEAD> <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =charset=3Diso-8859-1">
<TITLE>RE: Date comparison question</TITLE> </HEAD> <BODY>
<P><FONT SIZE=3D2>> -----Original Message-----</FONT> <BR><FONT SIZE=3D2>> From: Lisa Yates [<A = HREF=3D"mailto:cosnit_at_creighton.edu">mailto:cosnit_at_creighton.edu</A>]</F=
ONT> <BR><FONT SIZE=3D2>> Sent: lundi, 8. janvier 2001 11:27</FONT> <BR><FONT SIZE=3D2>></FONT> <BR><FONT SIZE=3D2>> Why doesn't this query ever return...</FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> where run_date =3D to_date('01-03-2001 =16:34:59','mm-dd-yyyy </FONT>
<BR><FONT SIZE=3D2>> hh24:mi:ss')</FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> but this query does....</FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> where to_char(run_date) =3D =to_char(to_date('01-03-2001</FONT>
<BR><FONT SIZE=3D2>> 16:34:59','mm-dd-yyyy hh24:mi:ss'))</FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> and so does this query....</FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> where to_char(run_date,'mm-dd-yyyy hh24:mi:ss') ==3D '01-03-2001 </FONT>
<BR><FONT SIZE=3D2>> 16:34:59'</FONT> </P> <BR>
<P><FONT SIZE=3D2>I was able to duplicate your results by inserting a =
row in a table with a "negative" date (aka a "BCE" =
date).</FONT>
</P>
<P><FONT SIZE=3D2>SQL> create table t (d date) ;</FONT> </P>
<P><FONT SIZE=3D2>Table created.</FONT>
</P>
<P><FONT SIZE=3D2>SQL> insert into t (d) values (to_date = ('-2001/01/03 16:34:59', 'SYYYY/MM/DD HH24:MI:SS')) ;</FONT> </P>
<P><FONT SIZE=3D2>1 row created.</FONT>
</P>
<P><FONT SIZE=3D2>SQL> select count (*)</FONT> <BR><FONT SIZE=3D2> 2 from t</FONT> <BR><FONT SIZE=3D2> 3 where d =3D to_date('01-03-2001 =16:34:59','mm-dd-yyyy hh24:mi:ss') ;</FONT> </P>
<P><FONT SIZE=3D2> COUNT(*)</FONT> <BR><FONT SIZE=3D2>----------</FONT> <BR><FONT SIZE=3D2> =0</FONT>
<P><FONT SIZE=3D2>SQL> select count (*)</FONT> <BR><FONT SIZE=3D2> 2 from t</FONT> <BR><FONT SIZE=3D2> 3 where to_char(d) =3D =to_char(to_date('01-03-2001 16:34:59','mm-dd-yyyy hh24:mi:ss'))</FONT> <BR><FONT SIZE=3D2> 4 ;</FONT> </P>
<P><FONT SIZE=3D2> COUNT(*)</FONT> <BR><FONT SIZE=3D2>----------</FONT> <BR><FONT SIZE=3D2> =1</FONT>
<P><FONT SIZE=3D2>SQL> select count (*)</FONT> <BR><FONT SIZE=3D2> 2 from t</FONT> <BR><FONT SIZE=3D2> 3 where to_char(d,'mm-dd-yyyy =hh24:mi:ss') =3D '01-03-2001 16:34:59' ;</FONT> </P>
<P><FONT SIZE=3D2> COUNT(*)</FONT> <BR><FONT SIZE=3D2>----------</FONT> <BR><FONT SIZE=3D2> =1</FONT>
<BR><FONT SIZE=3D2>select count (*)</FONT> <BR><FONT SIZE=3D2>from t</FONT> <BR><FONT SIZE=3D2>where d =3D to_date('01-03-2001 =16:34:59','mm-dd-yyyy hh24:mi:ss') ;</FONT> </P>
<P><FONT SIZE=3D2>Jacques R. Kilcho=EBr</FONT> <BR><FONT SIZE=3D2>(949) 754-8816</FONT> <BR><FONT SIZE=3D2>Quest Software, Inc.</FONT> </P> <P><FONT SIZE=3D2>8001 Irvine Center Drive</FONT><BR><FONT SIZE=3D2>Irvine, California 92618</FONT> <BR><FONT SIZE=3D2>U.S.A.</FONT> Received on Mon Jan 08 2001 - 14:04:02 CST
![]() |
![]() |