문제

I need to store a TV guide in MYSQL and I was thinking something like this:

channel_id         day      start_time  end_time

AMC Breaking Bad:) Monday   19:00:00    20:30:00

Other Program      Saturday 09:30:00    12:30:00

end_time and start_time are TIME fields and store HOURS.

My problem and questions is:

How can I get from MYSQL what programs are watching NOW()? I don't know how to compare the hours. I done some test, but i get nothing.

Hope you understand my English! Thanks Guys!

도움이 되었습니까?

해결책

I think you are asking how I can get a list of programs that are on right now where NOW is greater than or equal to the start_time and less than the end_time. With those assumptions here is the SQL:

SELECT * FROM tv_guide
WHERE CURTIME() BETWEEN start_time AND end_time;

EDIT: As @Corbin notes, you will need to check the day.

다른 팁

SELECT * FROM shows WHERE CURRENT_TIME() BETWEEN start_time AND end_time;

You'll probably also want to check the day as well, but that's just another where clause (AND day = 'Friday').

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top