<p>We are now using NHibernate to connect to different database base on where our software is installed.  So I am porting many SQL Procedures to Oracle.</p>

<p>SQL Server has a nice function called DateDiff which takes a date part, startdate and enddate.</p>

<p>Date parts examples are day, week, month, year, etc. . . </p>

<p>What is the Oracle equivalent?</p>

<p>I have not found one do I have to create my own version of it?</p>

<p><strong>(update by Mark Harrison)</strong> there are several nice answers that explain Oracle date arithmetic.  If you need an Oracle datediff() see Einstein's answer.  (I need this to keep spme SQL scripts compatible between Sybase and Oracle.)  Note that this question applies equally to Sybase.</p>

Tom's article is very old.  It only discusses the DATE type.  If you use TIMESTAMP types then date arithmetic is built into PL/SQL.
http://www.akadia.com/services/ora_date_time.html
```
```
DECLARE
ts_a timestamp;
ts_b timestamp;
diff interval day to second;
BEGIN
  ts_a := systimestamp;
  ts_b := systimestamp-1/24;
  diff := ts_a - ts_b;
  dbms_output.put_line(diff);
END;
+00 01:00:00.462000
```
```
or
```
```
DECLARE
ts_b timestamp;
ts_a timestamp;
date_part interval day to second;

BEGIN
  ts_a := systimestamp;
  date_part := to_dsinterval('0 01:23:45.678');
  ts_b := ts_a + date_part;
  dbms_output.put_line(ts_b);
END;

04-SEP-08 05.00.38.108000 PM
```
```