0

I have a database table like the figure shown below,

enter image description here

what i want is write a query to get the current system time is in which time slot. As the result i want to retrieve the line of the relevant time slot. Is there anyone can help me with this?

Mahedi Sabuj
  • 2,894
  • 3
  • 14
  • 27
Miu 1994
  • 28
  • 5
  • 2
    mysql date/time "math" is easy. `where timevalue BETWEEN earliertime AND latertime`. but you don't have time values in your db. you have **STRINGS**, and now you're in for a lot of pain converting all those strings to proper date/time values. – Marc B Jun 28 '16 at 16:44
  • 2
    And in bigger picture terms, this is not a jobs board. We are not here to "help" you do your job. You write code, we (maybe) try help fix it. – Marc B Jun 28 '16 at 16:45
  • i can change them anytime.. because i'm trying this only for testing purposes – Miu 1994 Jun 28 '16 at 16:52
  • You can use the logic: http://stackoverflow.com/questions/1504494/find-if-current-time-falls-in-a-time-range#21343435 – Mahedi Sabuj Jun 28 '16 at 17:03

1 Answers1

0

create table in following format

CREATE TABLE TEST (tid int,tname varchar(10),starttime time,endtime time);

INSERT INTO TEST values (1,"a", "00:00:00","07:00:00");
INSERT INTO TEST values (2,"b", "07:00:00","19:00:00");
INSERT INTO TEST values (3,"c", "19:00:00","23:59:50");

s

elect * from TEST where starttime<time(now()) and endtime>time(now());

    +------+-------+-----------+----------+
    | tid  | tname | starttime | endtime  |
    +------+-------+-----------+----------+
    |    3 | c     | 19:00:00  | 23:59:50 |
    +------+-------+-----------+----------+
    1 row in set (0.00 sec)
Mahesh Madushanka
  • 2,902
  • 2
  • 14
  • 28