P
P
Pavel Chuev2016-02-23 21:40:18
PHP
Pavel Chuev, 2016-02-23 21:40:18

Disagreements CURTIME and SUBTIME?

I wrote in php something similar to a radio based on VKontakte and its API. It works like this: I parse the tracks from the playlist into the database and take a random song and send it to the status (I also specify CURTIME to avoid repetitions). But the problem is this: songs played for example from 18:00 to 23:59 will not be repeated until 21:00 the next evening. Thus, the playlist is drastically cut and there are simply not enough songs to play.
This is how I pull the songs that were last played three hours ago:

SELECT * FROM `music` WHERE `time` <= SUBTIME(CURTIME(), '03:00:00') AND 1 ORDER BY RAND() LIMIT 1

How to fix such a cant with the playback time of songs?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Savostin, 2016-02-23
@savostin

datetime?

I
Igor, 2016-02-23
@unitby

Options may vary. An example solution (look at the logic) is:

select if(curtime() < '12:00:00', addtime(curtime(),'03:00:00'), subtime(curtime(),'03:00:00'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question