Basically Date is used to extract the data from a table in database . Suppose you want to find and extract the data from database for particular date then you can do this with the Date statement .
Example ->
Table name -> student
- Student_name Student_Age Student_Id Date
- Mukesh 23 1 2013-12-12
- Ayush 24 2 2013-12-13
- Ishan 20 4 2012-12-12
Student_name Student_Age Student_Id Date
Mukesh 23 1 2013-12-12
Ayush 24 2 2013-12-13
Ishan 20 4 2012-12-12
Suppose you want to extract the information of date 2013-12-12 and more than this .
- select * from student where Date >= 2013-12-12 ;
select * from student where Date >= 2013-12-12 ;
Output :
- Student_name Student_Age Student_Id Date
- Mukesh 23 1 2013-12-12
- Ayush 24 2 2013-12-13
- Ishan 20 4 2012-12-12
Student_name Student_Age Student_Id Date
Mukesh 23 1 2013-12-12
Ayush 24 2 2013-12-13
Ishan 20 4 2012-12-12
Now suppose you want to retrieve the data of date after than 2013-12-12 and before 2013-12-13 .
- select * from student where Date < ' 2013-12-13 ' and Date >= ' 2013-12-12 ' ;
select * from student where Date < ' 2013-12-13 ' and Date >= ' 2013-12-12 ' ;
Output :
- Student_name Student_Age Student_Id Date
- Mukesh 23 1 2013-12-12
- Ishan 20 4 2012-12-12
Student_name Student_Age Student_Id Date
Mukesh 23 1 2013-12-12
Ishan 20 4 2012-12-12
If you want to compare the dates then you have to use Between operator between them like this..see below :
Syntax :
- select * from student where Date Between ?2012-12-12 and ?2013-12-12 ;
select * from student where Date Between ?2012-12-12 and ?2013-12-12 ;
Suppose you want to retrieve only one date from database then you can also do :
- select * from student where cast ( datedifference (day , 0 , yourdate ) as datetime ) = ?2012-12-12?
select * from student where cast ( datedifference (day , 0 , yourdate ) as datetime ) = ?2012-12-12?
1 Comment(s)