Home Sql Sqldate Mysql Date Search

Related Tutorials


 
 

Share on Google+Share on Google+

Mysql Date Search

Advertisement
In this Tutorial you will learn how to' search Date in Mysql'. To understand this example, we create a table 'employee' with required fieldname and datatype respectively.

Mysql Date Search

     

In this Tutorial you will learn how to' search Date in Mysql'. To understand this example, we create a table 'employee' with required fieldname and datatype respectively. The Table employee has a 'empid' as Primary Key. The keyword create table employee is used to create a table 'employee'.

Create table "employee":

CREATE TABLE `employee` ( 
`id` bigint(20) NOT NULL auto_increment, 
`emp_name` varchar(100) NOT NULL, 
`emp_dob` date default NULL, 
PRIMARY KEY (`id`) 

Query to insert the record in the table "employee":

Now the Query insert into is used to add the records or  rows into table 'employee' 

insert into employee (emp_name,emp_dob)values('Sourabh','1985-11-07');
insert into employee (emp_name,emp_dob)values('Vineet','1983-11-07');
insert into employee (emp_name,emp_dob)values('Girish','1984-10-06');
insert into employee (emp_name,emp_dob)values('Sourabh','1982-01-05');

Query to retrieve the records from table "employee":

To view the details of the records from table 'employee' we run select query to retrieve it.

select * from employee;

Output:

mysql> select * from employee
+----+----------+------------
| id | emp_name | emp_dob
+----+----------+------------
| 1 | Sourabh | 1985-11-07
| 2 | Vineet | 1983-11-07
| 3 | Girish | 1984-10-06
| 4 | Sourabh | 1982-01-05
+----+----------+------------
4 rows in set (0.00 sec)

Query to Search record by Date:

The Query below returns the records details from table employee whose emp_dob is '1985-11-07'.

select * from employee where emp_dob='1985-11-07'

Output :

+----+----------+------------+
| id | emp_name | emp_dob |
+----+----------+------------+
| 1 | Sourabh | 1985-11-07 |
+----+----------+------------+
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



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: January 20, 2009

Related Tutorials

Discuss: Mysql Date Search  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com