Home » SQL & PL/SQL » SQL & PL/SQL » trunc(sysdate-1) or trunc(sysdate)-1 (10.2)
trunc(sysdate-1) or trunc(sysdate)-1 [message #564318] Wed, 22 August 2012 10:32 Go to next message
lott42
Messages: 80
Registered: June 2010
Member
Are these two date formats equivalent?? Is one format preferred over the other??

SELECT trunc(SYSDATE - 1) date1, trunc(SYSDATE) - 1 date2 FROM dual


Result:
DATE1	   DATE2
8/21/2012  8/21/2012

Re: trunc(sysdate-1) or trunc(sysdate)-1 [message #564320 is a reply to message #564318] Wed, 22 August 2012 10:47 Go to previous messageGo to next message
Solomon Yakobson
Messages: 1797
Registered: January 2010
Senior Member
Six or half a dozen? TRUNC(date_expression) is beginning of day of date_expression. Now sysdate - 1 is same time yeaterday. Therefore trunc(sysdate - 1) is beginning of day yesterday. trunc(sysdate) is beginning of day today. And trunc(sysdate) - 1 again is beginning of day yesterday.

SY.
Re: trunc(sysdate-1) or trunc(sysdate)-1 [message #564322 is a reply to message #564318] Wed, 22 August 2012 11:03 Go to previous message
Michel Cadot
Messages: 57613
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
And the result is clearer like:
SQL> SELECT trunc(SYSDATE - 1) date1, trunc(SYSDATE) - 1 date2 FROM dual;
DATE1               DATE2
------------------- -------------------
21/08/2012 00:00:00 21/08/2012 00:00:00

Regards
Michel
Previous Topic: PRAGMA AUTONOMOUS_TRANSACTION with DBLINK
Next Topic: SQL that gives me Jobs due tomorrow?
Goto Forum:
  


Current Time: Sun Apr 20 09:25:50 CDT 2014

Total time taken to generate the page: 0.08054 seconds