Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2006
    Posts
    2

    Unanswered: compare time in mysql

    I have created table named as schedule in mysql, having 3 columns

    Code:
    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');
    what I am trying is to find out record which comes in between given time such

    Code:
    Select Count(*) from Schedule where fromdate>='2012-08-12 10:30:00' and todate<='2012-08-15 19:17:00';
    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

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    check your data
    the SQL is working as it should be
    or you could remove the >= and <=
    to
    Code:
    Select Count(*) from Schedule where fromdate > '2012-08-12 10:30:00' and todate < '2012-08-15 19:17:00';
    with these sort of problems its usually best to examine the rows returned by replacing the aggregate function count(*) with * and examine the rows returned to try to understand why what you are getting isn't what you are expecting.
    Last edited by healdem; 08-17-12 at 07:09.
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •