compare time in mysql

Discussion in 'MySQL' started by bamboat_3, Aug 17, 2012.

  1. #1
    I have created table named as schedule in mysql, having 3 columns
    
    
    CREATE TABLE SCHEDULE ID int(11), FromDate TIMESTAMP, TODATE TimeSTAMP);  insert into schedule(id,fromdate,todate) values (1,'2012-08-12 10:30:00','2012-08-15  18:17:00');
    
    
    Code (markup):
    what I am trying is to find out record which comes in between given time such

    
    Select Count(*) from Schedule where fromdate>='2012-08-12 10:30:00' and todate<='2012-08-15 19:17:00';
    Code (markup):
    The above query suppose to return zero but it returning one that means something I am doing wrong to find out the number of records come between given times
    Please help me out to solve this issue . Looking forward to your kind response

    Regards M.A.Bamboat
     
    bamboat_3, Aug 17, 2012 IP
  2. plussy

    plussy Peon

    Messages:
    152
    Likes Received:
    5
    Best Answers:
    9
    Trophy Points:
    0
    #2
    right 2 things

    firstly you need to be more consistent. mysql is case sensitive and a table SCHEDULE is different from schedule. The same with columns.

    secondly the query does exactly what you say. the dates that you are inserting into the db are equal to the ones in your query.

    if you change the the from date to be further in the past ie 2012-08-12 09:30:00 or the to date to a later date ie 2012-08-16 19:17:00 you will see that you will get 0 as result.
     
    plussy, Sep 28, 2012 IP