Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • SQL Date Statement

    • 0
    • 1
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 118
    Comment on it

    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
    

    Suppose you want to extract the information of date 2013-12-12 and more than this .

    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
    

    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 ' ; 
    

    Output :

    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 ;
    

    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?
    

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: