SQL Between Timestamp

A timestamp is used to catch the dates and times.


 
Ads

SQL Between Timestamp

     

A timestamp is used to catch the dates and times. 

Understand with Example

The Tutorial illustrate an example to create a SQL Between Timestamp. The table 'Stu_Table' is created with the help of create statement. 

Create Table

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

Insert Date Into Stu_Table

Now insert into statement is used to add the records or rows into a 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 given below query return you the list of records enlisted in the select statement. The Where clause restrict the select query and return you the records from stu_Dob column 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

Share on Google+Share on Google+

SQL Between Timestamp

Posted on: December 20, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: SQL Between Timestamp  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
Shadab Shah
May 22, 2012
Why???

When we were having the datatype as datetime then why there was a need of timestamp datatype.
Musaab N Abuqamar
December 17, 2012
Times

how to split time in Sql

Ads

 

Ads