- 02-22-2009 05:24 PM #1
DATEDIFF function in Oracle like SQL Server
Hi guys, hope everyone is good
Can someone tell me the equivalent for the SQL Server DATEDIFF function in Oracle
For example, in Microsoft SQl server, I can do
This gives the difference in number of days between date_var and GETDATE(). Now what's the equivalent in Oracle. If i doCode :SELECT DATEDIFF(dd, date_var , GETDATE())
, it gives me an error ORA-00932: inconsistent datatypes: expected NUMBER got INTERVAL, what am i missing here?Code :select date_var-sysdate from temp
Regards,
Simona
- Club-Oracle Complementary E-Books and Magazines
Get your free Complementary Copy of Oracle Magazine
You can also browse the Free Magazines and E-Books section to see the complete list of free magazines, e-books and Whitepapers.
- 02-23-2009 02:49 AM #2
Re: DATEDIFF function in Oracle like SQL Server
did u say "got interval", try this
Code :select (SYSTIMESTAMP - date_var) from temp
- 02-23-2009 03:09 AM #3
Re: DATEDIFF function in Oracle like SQL Server
First all , you didn't mentioned about the data type of date_var.
If it is non-date datatype , that needs to be converted to date while doing such operations.
Code :SQL> SELECT SYSDATE - TO_DATE('20081205','YYYYMMDD') datediff FROM DUAL; DATEDIFF ---------- 80.4018519 SQL> SELECT TRUNC(SYSDATE) - TO_DATE('20081205','YYYYMMDD') datediff FROM DUAL; DATEDIFF ---------- 80 SQL>Last edited by rajavu; 02-23-2009 at 03:13 AM.

Raj.
Similar Threads
-
Problem In Data Base Creation... Oracle 10g server in windows server 2008
By fouta in forum Installation - WindowsReplies: 1Last Post: 07-07-2010, 04:16 PM -
Inline Function vs Function
By learnerSaumya in forum SQL PL/SQLReplies: 5Last Post: 04-29-2010, 06:48 PM -
Generic DateDiff query for Oracle and SQL server
By SPIND in forum SQL PL/SQLReplies: 3Last Post: 05-15-2009, 11:58 AM -
Oracle 9i SQL DECODE Function Limitation
By ygsunilkumar in forum SQL PL/SQLReplies: 6Last Post: 05-11-2009, 06:18 AM -
Aggregate function in SQL Server
By sowmyav in forum Other DatabasesReplies: 4Last Post: 01-16-2009, 06:12 AM


