Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-10-22
4
Medium Priority
?
372 Views
Last Modified: 2013-10-22
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
Comment
Question by:srikanth_saladi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39591077
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1500 total points
ID: 39591089
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
 

Author Closing Comment

by:srikanth_saladi
ID: 39591283
Thanks Ray_Paseur,

I made a mistake by not putting older time first.Once i changed it works for me
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39591426
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we’ll look at how to deploy ProxySQL.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question