Records between current date and 2 weeks from the current date? [message #378348] |
Tue, 30 December 2008 02:09 |
msg2ajay
Messages: 51 Registered: June 2007 Location: KUALA LUMPUR
|
Member |
|
|
hi,
i am trying to get data with some condition like
"the difference of two dates <= 14"
select * from t_dds_contact where TRUNC(TO_DATE(expected_first_commission_d,'DD-MM-YYYY') - TO_DATE(sysdate,'DD-MM-YYYY')) <= 14;
I want the data which is less that or equal to 14, where I am getting all values like negative values as well. Any suggestions...
ThankQ
[MERGED by LF]
[Updated on: Wed, 31 December 2008 02:40] by Moderator Report message to a moderator
|
|
|
|
|
Re: difference between two dates with condition [message #378446 is a reply to message #378348] |
Tue, 30 December 2008 08:12 |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
msg2ajay wrote on Tue, 30 December 2008 03:09 |
TO_DATE(sysdate,'DD-MM-YYYY')
|
This is invalid. SYSDATE is a DATE. Trying to convert it to a date, only bad things can happen.
FOO SCOTT>select to_date(sysdate,'dd-mon-yyyy') from dual;
select to_date(sysdate,'dd-mon-yyyy') from dual
*
ERROR at line 1:
ORA-01843: not a valid month
|
|
|
Re: difference between two dates with condition [message #378494 is a reply to message #378446] |
Tue, 30 December 2008 14:27 |
Olivia
Messages: 519 Registered: June 2008
|
Senior Member |
|
|
Trying to convert it to a date, only bad things can happen- Agree.
But I didn't get any error!
hr@ORAFAQ.US.ORACLE.COM> select to_date(sysdate,'dd-mon-yyyy') from dual;
TO_DATE(S
---------
31-DEC-08
Elapsed: 00:00:00.00
hr@ORAFAQ.US.ORACLE.COM> select * from v$version
2 ;
BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
PL/SQL Release 9.2.0.1.0 - Production
CORE 9.2.0.1.0 Production
TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
NLSRTL Version 9.2.0.1.0 - Production
Elapsed: 00:00:00.01
hr@ORAFAQ.US.ORACLE.COM>
[Updated on: Tue, 30 December 2008 15:25] by Moderator Report message to a moderator
|
|
|
|
Re: difference between two dates with condition [message #378504 is a reply to message #378348] |
Tue, 30 December 2008 15:13 |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
Just to append to Michel's reply: if it does not fail, you get the result date truncated to smallest time piece in the used date format (day in your case). It is the side-effect of executed implicit conversion. It may be fine if you count with it; but I would rather use TRUNC function and keep the code understandable at the first sight.
|
|
|
Re: difference between two dates with condition [message #378509 is a reply to message #378494] |
Tue, 30 December 2008 15:24 |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
Olivia wrote on Tue, 30 December 2008 15:27 | Trying to convert it to a date, only bad things can happen- Agree.
But I didn't get any error!
|
This falls into the famous proverb (I say "proverb" because I don't know that correct word. Axiom maybe?)
Showing that it works 1000 times does not prove that it is valid. Showing that it fails just once proves that it is invalid.
|
|
|
Re: difference between two dates with condition [message #378517 is a reply to message #378504] |
Tue, 30 December 2008 15:54 |
Olivia
Messages: 519 Registered: June 2008
|
Senior Member |
|
|
hr@ORAFAQ.US.ORACLE.COM> select to_char(sysdate,'dd-mon-yyyy hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'DD-
--------------------
31-dec-2008 03:21:05
Elapsed: 00:00:00.00
hr@ORAFAQ.US.ORACLE.COM>
1* select to_char(to_date(sysdate,'dd-mon-yyyy hh24:mi:ss'),'dd-mon-yyyy hh24:mi:ss') from dual
hr@ORAFAQ.US.ORACLE.COM> /
TO_CHAR(TO_DATE(SYSD
--------------------
31-dec-0008 00:00:00
Elapsed: 00:00:00.00
Thanks
|
|
|
|
|
|
|
|
|
Re: difference between two dates with condition [message #378657 is a reply to message #378597] |
Wed, 31 December 2008 04:26 |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
Michel Cadot wrote on Wed, 31 December 2008 08:16 | And then?
What is the purpose of your post?
|
In my opinion, Olivia just demonstrates that the truncating may happen, as I mentioned. And that I was not correct, as the date is truncated to smallest time piece in NLS_DATE_FORMAT (not the used format). Of course, only if the TO_DATE function does not fail.
|
|
|
|
|