For a 15-minute interval, the request might look like this:
SELECT FLOOR( (UNIX_TIMESTAMP() - UNIX_TIMESTAMP('2015-10-10 15:00:00')) / (15 * 60) ) AS begin_15, CEILING( (UNIX_TIMESTAMP() - UNIX_TIMESTAMP('2015-10-10 15:00:00')) / (15 * 60) ) AS finish_15, FROM_UNIXTIME( UNIX_TIMESTAMP('2015-10-10 15:00:00') + FLOOR((UNIX_TIMESTAMP() - UNIX_TIMESTAMP('2015-10-10 15:00:00')) / (15 * 60)) * (15 * 60) ) AS date_begin_15, FROM_UNIXTIME( UNIX_TIMESTAMP('2015-10-10 15:00:00') + CEILING((UNIX_TIMESTAMP() - UNIX_TIMESTAMP('2015-10-10 15:00:00')) / (15 * 60)) * (15 * 60) ) AS date_finish_15; +----------+-----------+---------------------+---------------------+ | begin_15 | finish_15 | date_begin_15 | date_finish_15 | +----------+-----------+---------------------+---------------------+ | 20579 | 20580 | 2016-05-11 23:45:00 | 2016-05-12 00:00:00 | +----------+-----------+---------------------+---------------------+
The date of reference is chosen '2015-10-10 15:00:00', the current date is taken as the checked date. For other intervals, the digit in the request should replace the digit 15 with a digit corresponding to the number of minutes in the interval.