Oracle comparing dates : dates, oracle, date comparison in oracle pl/sql

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Buffer 0 Email -- Filament.io 0 Flares ×

How to compare dates in oracle?There are a number of ways you can compare two dates in oracle to check which is greater or which is small.This is particularly useful when we do operations based on certain date conditions.This is used along with to_date and other date functions.
The following example illustrates the date comparison in Oracle pl/sql.

SQL> SET SERVEROUTPUT ON;
SQL>
SQL> -- Created on 11/19/2008 by Globinch PLSQLTIPS
SQL> declare
-- Local variables here
test_Date DATE;
begin
   --- Initialize the test date a future date.
      test_Date := to_date('12/12/2008','DD/MM/YYYY');
      if test_date>sysdate then
         dbms_output.put_line('The date :' || test_Date||': This is a future date!');
      end if;
      ----Now subtract 60 days from the test date
      test_Date := test_Date - 60;
      if test_date<sysdate
            dbms_output.put_line('The date :' || test_Date||': This is a Past date!');
      end if;
     --- Now make test date current date
     test_Date :=  sysdate;
     if test_date = sysdate then
         dbms_output.put_line('The date :' || test_Date||': Date is a today!');
     end if;
 end;
/

The date :12-DEC-08: This is a future date!
The date :13-OCT-08: This is a Past date!
The date :19-NOV-08: Date is a today!

PL/SQL procedure successfully completed.

SQL>

Related articles on oracle DATE , TIMESTAMP etc

Technorati Tags:
, , , , ,

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Buffer 0 Email -- Filament.io 0 Flares ×

1 thought on “Oracle comparing dates : dates, oracle, date comparison in oracle pl/sql

  1. Pingback: Oracle Max(Date) function usage-SQL max date | SQL and PLSQL

Leave a Reply

Your email address will not be published. Required fields are marked *

Paged comment generated by AJAX Comment Page