how to check whether time is in between given range of time intervals

I want to compare a db column which stores time in format 09:30:14 against a php variable which stores time in same format.I want to check whether the time stored in dbcolumn is less than 2 miutes of time stored in php using mysql.I want to retireve some values based on this check
   
    $ordertime_present = 09:32:14;
    $ordertime_before = 09:30:14;
   
    $sql = "select count(keyid) as key_id_count from key_master where orderdate='$orderdate'
           and ordertime between '$ordertime_present' and '$ordertime_before'";
srikanth saladiAsked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
It would seem more natural to me to have the older time first in the between clause.  But that aside, why not combine the orderdate and ordertime into a single DATETIME column?  That would give a better design in my opinion.

$ordertime_present = date('H:i:s');
$ordertime_before = date('H:i:s', strtotime("NOW - 2 MINUTES"));
$sql = "select count(keyid) as key_id_count from key_master where orderdate='$orderdate'
           and ordertime between '$ordertime_before' and '$ordertime_present'"; 

Open in new window

0
 
Ray PaseurCommented:
0
 
srikanth saladiAuthor Commented:
Thanks Ray_Paseur,

I made a mistake by not putting older time first.Once i changed it works for me
0
 
Ray PaseurCommented:
I see you're new here, @srikanth_saladi.  Please review the grading guidelines.  Since the "default" grade is "A", when you give a lower grade you are also expected to explain why the answer was deficient.
http://support.experts-exchange.com/customer/portal/articles/481419

If you want to change the grade, just post back.  Thanks and regards, ~Ray
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.