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
    • 186
    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

    1. Student_name Student_Age Student_Id Date
    2. Mukesh 23 1 2013-12-12
    3. Ayush 24 2 2013-12-13
    4. Ishan 20 4 2012-12-12

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

    1. select * from student where Date >= 2013-12-12 ;

    Output :

    1. Student_name Student_Age Student_Id Date
    2. Mukesh 23 1 2013-12-12
    3. Ayush 24 2 2013-12-13
    4. 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 .

    1. select * from student where Date < ' 2013-12-13 ' and Date >= ' 2013-12-12 ' ;

    Output :

    1. Student_name Student_Age Student_Id Date
    2. Mukesh 23 1 2013-12-12
    3. 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 :

    1. 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 :

    1. 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
Reset Password
Fill out the form below and reset your password: