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
- ALTER TABLE to ADD PRIMARY KEY in Oracle| Oracle ALTER TABLE
- oracle date difference | date difference in sql an…
- DATE Data type in Oracle|Oracle Dates and Times|Dates in Oracle
- Formatting date in SQL (Oracle) -Simple date forma…
- Database Schema | Oracle Schema Objects | What is database schema?
- Autonomous Transactions in PL/SQL
- SQL – Transaction Statements -Transaction Manageme…
- Savepoints In SQL Transactions. – SAVEPOINT
- Oracle Tablespace, and Datafiles – Introduction
- Formatting date in SQL (Oracle) -Simple date forma…
- FINDING database objects, finding valid and INVALI…
Technorati Tags:
Oracle comparing dates, dates, oracle, Comparing Dates in oracle pl/sql, sql dates, date comparison
Pingback: Oracle Max(Date) function usage-SQL max date | SQL and PLSQL