Home Sql Sqldate SQL Between Timestamp
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

SQL Between Timestamp

Advertisement
SQL Between Timestamp is used to return the time records of table in database.

SQL Between Timestamp

     

SQL Between Timestamp is used to return the time records of table in database.

Understand with Example

The Tutorial map you to understand and illustrate an example from 'SQL Between Timestamp'.To understand and grasp the example we create a table 'Stu_Table' with required tablefields and datatypes respectively.

 

 

 

Create Table

CREATE TABLE Stu_Table (
	     Stu_Id varchar(2),
	     Stu_Name varchar(10),
             Stu_Dob timestamp NOT NULL );

Insert Date Into Stu_Table

The insert into is used to add the records or rows to the table 'Stu_Table'.

Insert Into Stu_Table Values('1', 'Komal', '1984-10-27');
Insert Into Stu_Table Values('2', 'ajay', '1985-04-19');
Insert Into Stu_Table Values('3', 'Santosh', '1986-11-16');

Stu_Table

+--------+----------+---------------------+
| Stu_Id | Stu_Name | Stu_Dob             |
+--------+----------+---------------------+
| 1      | Komal    | 1984-10-27 00:00:00 |
| 2      | ajay     | 1985-04-19 00:00:00 |
| 3      | Santosh  | 1986-11-16 00:00:00 |
+--------+----------+---------------------+

Query

The Query below given is used to show only those records include time whose stu_dob lies between '1984-01-01' And '1986-1-1'.

Select * From Stu_Table
Where Stu_Dob Between '1984-01-01' And '1986-1-1';

Result

+--------+----------+---------------------+
| Stu_Id | Stu_Name | Stu_Dob             |
+--------+----------+---------------------+
| 1      | Komal    | 1984-10-27 00:00:00 |
| 2      | ajay     | 1985-04-19 00:00:00 |
+--------+----------+---------------------+
Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 17, 2009

Ask Questions?    Discuss: SQL Between Timestamp  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Farooq
April 18, 2012
Query

the above scenario is the good example for what i am looking for. However what if when there are students whose date of births are falling in exactly on either start or end parameter/date. and how will be the results then. Please explain the same scenario with the above given comment.
DMCA.com