Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Sql Sqldate Mysql Date Ranges

Related Tutorials


 
 

Share on Google+Share on Google+

Mysql Date Ranges

Advertisement
Mysql Date Ranges is useful when you want to see the records between two dates.

Mysql Date Ranges

     

Mysql Date Ranges is useful when you want to see the records between two dates.

Understand with Example

The Tutorial grasps you the elaborative example from 'Mysql Date Ranges'. To understand this example we create a table 'userform' with required fieldnames and datatypes respectively. The table 'userform' has a Primary Key Id. 

Query to create table "userform":

CREATE TABLE `userform` ( 
`ID` int(11) NOT NULL auto_increment, 
`username` varchar(100) default NULL, 
`fname` varchar(100) default NULL, 
`email` varchar(100) default NULL, 
`today` date default NULL, 
PRIMARY KEY (`ID`), 
KEY `date_index` (`today`) 
)

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

The Query insert into is used to add the records or rows to the table "userform".

insert into userform (Id,username,fname,email,today) values (1,'vineet','vineet','vineet@roseindia.net','2008-12-08');
insert into userform (Id,username,fname,email,today) values (1,'saurabh','saurabh','srbh.saurabh@gmail.com,'2008-12-18');
insert into userform (Id,username,fname,email,today) values (1,'amit','Amit','amit@gmail.com','2008-12-08');
insert into userform (Id,username,fname,email,today) values (1,'suman','Suman','suman@yahoo.com,'2009-01-02');
insert into userform (Id,username,fname,email,today) values (1,'amar','Amar','amar@rediffmail.com','2009-01-08');


Query to show the records between two dates 

The Query is used to return the records between the two dates specified in Where Clause from the table 'userform'. 

mysql> select * from userform where today>='2008-12-08' and today <='2009-01-0
+----+----------+---------+------------------------+------------+
| ID | username | fname | email | today |
+----+----------+---------+------------------------+------------+
| 1 | vineet | vineet | vineet@roseindia.net | 2008-12-08 |
| 2 | saurabh | saurabh | srbh.saurabh@gmail.com | 2008-12-18 |
| 3 | amit | Amit | amit@gmail.com | 2009-01-01 |
| 4 | suman | Suman | suman@yahoo.com | 2009-01-02 |
| 5 | amar | Amar | amar@rediffmail.com | 2009-01-08 |
+----+----------+---------+------------------------+------------+
5 rows in set (0.00 sec)
Advertisements

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 21, 2009

Related Tutorials

Discuss: Mysql Date Ranges  

Post your Comment


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