Solved

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

Posted on 2013-10-22
4
358 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
  • 3
4 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39591077
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 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 108

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now