How to Retrieve the Records Based on a Date from Oracle Database?
Last Updated :
28 Oct, 2021
DATE is a SQL-defined data type that is used to store dates in a column, different database management systems store dates in different formats. MySQL uses 3 bytes to store dates. It stores DATE in a format like 'YYYY-MM-DD'. The DATE value ranges from 1000-01-01 to 9999-12-31. Oracle database management system stores DATE in a format like 'MM-DD-YYYY'.
Here 'MM' is month, 'DD' is day and 'YYYY' is the year. Microsoft SQL Server stores date in the same format as MySQL stores it.
Step 1: Create a database
Query:
CREATE DATABASE geeksforgeeks;
Step 2: Let's create a table named employees.
Query:
CREATE TABLE employee
(emp_id INT, emp_fname VARCHAR(45),
emp_lname VARCHAR(45),join_date DATE,
PRIMARY KEY(emp_id));
Step 3: Now we will insert values in the employee table.
Query:
INSERT INTO employee VALUES
(100181, 'Utkarsh', 'Tyagi', '1996-01-31'),
(100182, 'Abhishek', 'Singh', '1996-03-21'),
(100183, 'Jake', 'Johnson', '1997-06-14'),
(100184, 'Abhimanyu', 'Rana', '1997-11-06'),
(100185, 'Akansha', 'Sharma', '1998-11-23'),
(100186, 'Priya', 'Yadav', '1999-10-10'),
(100187, 'Naina', 'Singhal', '2000-06-13');
Step 4: Now let's see the contents of our table.
Query:
SELECT * FROM employee;
Output:

Step 5: We want to print only those records whose join_date is '2000-06-13'.
- Retrieving records based on DATE using the '=' operator.
Query:
SELECT * FROM employee WHERE join_date = '2000-06-13';
Output:

We have only one employee whose join_date is on '2000-06-13'.
We will be using the same employee table that we have used in the above example. Now our task is to retrieve those records whose join_date is in the year 1996 irrespective of day and month.
Query:
SELECT * FROM employee WHERE join_date LIKE '1996-%';

So we have two records whose join_date is in the year 1996.
- Retrieving records based on DATE using BETWEEN keyword
We want to retrieve those records where join_date in between years 1996 and 1997.
Query:
SELECT * FROM employee WHERE join_date BETWEEN '1996-01-01' AND '1997-12-31';

So there are four employees who joined the company between that time interval.
Similar Reads
How to Migrate Data from SQL Server to Oracle Database?
The conversion of data from one database management system to another can be a difficult process, particularly when migrating from SQL Server to Oracle Database. In this article, We will learn about How to migrate data from SQL Server to Oracle database by providing clear and detailed procedures. Ov
4 min read
How to Fetch Data From Two Tables Based on Date in SQL?
In SQL, fetching data from multiple tables based on a specific date range is a common task. By using certain SQL operations, we can combine data from two different tables and filter the results based on a date condition. This method is particularly useful when working with multiple datasets and we n
3 min read
SQL Query to Delete a Data From a Table Based on Date
Many of the time we have to delete data based on the date. These dates can be some older dates. For this purpose, we can use delete query along with where clause. This approach helps us to delete some old data in our database. In this article, we are going to delete the data of employees based on th
2 min read
How to Select Data Between Two Dates and Times in SQL Server?
In SQL, some transactions need to be extracted based on their completion times and dates. Here, the DATETIME2 data type in SQL to perform such operations. For this article, we will be using the Microsoft SQL Server as our database. Note: Here, we will use the two dates and times given in the query a
2 min read
How to Retrieve Data from Multiple Tables in PL/SQL
PL/SQL is âProcedural Language extensions to the Structured Query Languageâ. SQL is a popular language for both querying and updating data in relational database management systems (RDBMS). PL/SQL adds many procedural constructs to SQL language to overcome some limitations of SQL. In addition, PL/SQ
5 min read
How to Write a SQL Query For a Specific Date Range and Date Time?
Managing date and time in SQL is a critical task for many real-world applications, especially when handling time-sensitive data such as logs, timestamps, and event records. SQL provides various tools and data types to work with date and time effectively. In this guide, we will focus on working with
4 min read
How to List All Tables in a Schema in Oracle Database?
In Oracle Database, listing all tables within a schema can be crucial for database management and analysis. we can use specific queries to retrieve information about tables in our schema. Below, we explore various queries to list tables, focusing on the SYSOBJECTS view that provides essential metada
3 min read
How to Extract Date From a TimeStamp in PostgreSQL
PostgreSQL is a powerful open-source relational database management system (RDBMS). PostgreSQL is well-known for its feature-rich capabilities, standardization, and adaptability. It supports a variety of data types, complex SQL queries, and ACID properties. PostgreSQL offers scalability and durabili
4 min read
How to Find Day Name From Date in SQL Server?
Finding the day name from a specific date is a common task in SQL Server, useful for generating reports, analyzing trends, or scheduling. SQL Server provides two primary methods such as the DATENAME() function and the FORMAT() function. In this article, We will learn about How to Find Day Name From
4 min read
SQL Query to Set First Day of the Week in a Database
In this article, we are going to write a SQL script to Set the first day of the week in a Database. Below is the implementation for the same. You should have MSSQL in your server. Query in SQL - A query is a request for data or information from a database table or combination of tables. This data ca
2 min read