C.topo
C.topo

Reputation: 17

Showing data from database 15 mnute earlier and stop showing it 15 minute late from the time set for it

$query = "SELECT title,time_strt,ampmstrt,time_end,ampmend
          FROM addfunction
          WHERE (NOW() + INTERVAL 15 MINUTE) BETWEEN time_strt AND time_end AND location = 'MAWAR ROOM'";

Upvotes: 0

Views: 48

Answers (2)

C.topo
C.topo

Reputation: 17

Ended doing it like this which show the data from database 15 minute earlier than time_strt and stop Showing after 15 minute have elapsed from the time_end. I changed the data type from DATETIME to TIME. Thanks to evryone and mostly @harley81!

WHERE date = CURDATE() AND time_strt <= (CURTIME() + INTERVAL 15 MINUTE) AND time_end >= (CURTIME() - INTERVAL 15 MINUTE) AND location = 'MAWAR ROOM'";

Upvotes: 0

harley81
harley81

Reputation: 192

topo,

i hope i understand it correctly...

select title,time_strt,ampmstrt,time_end,ampmend 
FROM addfunction 
where UNIX_TIMESTAMP(time_strt) >= (UNIX_TIMESTAMP(NOW()) - 15 * 60) 
and UNIX_TIMESTAMP(time_end) >= (UNIX_TIMESTAMP(NOW()) + 15 * 60) 
AND location = 'MAWAR ROOM';

This will found all rows start 15 minutes before time_strt and ends 15 minutes after time_end.

Upvotes: 1

Related Questions