Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 375
  • Last Modified:

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'";
0
srikanth saladi
Asked:
srikanth saladi
  • 3
1 Solution
 
Ray PaseurCommented:
0
 
Ray PaseurCommented:
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
 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now