Select time in Mysql

Asked

Viewed 42 times

-1

Good afternoon guys! All right?

I am developing a plugin that pulls from a database the television programs, it should pull by the time and show in a table the programs that are playing live, according to the system time (current time) and only change when starting the other program.

currently my select is like this:

SELECT *, DATE_FORMAT(horario, '%H:%i') as horario FROM wp_grade, 
(SELECT horario AS a FROM wp_grade WHERE horario <= '$gh_data' order by horario DESC LIMIT 1) AS b WHERE horario >=a ORDER BY horario

This select works only for the time, but does not take into account the date (day, month and year).

the table is like this:

create table wp_grade(
id int primary key,
programa varchar(50),
descricao text,
horario datetime);

what change it should make?

  • Test if the date in the grid is equal to the date of the system. In your case the date part of your datetime field horario. Use the function DATE(horario) = CURRENT_DATE.

1 answer

1

Below is an example:

Example

SELECT *, DATE_FORMAT(horario, '%H:%i') as horario FROM wp_grade, 
(SELECT horario AS a FROM wp_grade WHERE DATE(horario) = CURRENT_DATE 
 order by horario DESC LIMIT 1) AS b 
 WHERE horario >= a ORDER BY horario
  • Hello! then, keeps giving the same problem :( He can sort by time, but does not take the date (day, month and year) into account. For example, if you have the mouse program on 02/12/2020 at 00:15 and Eliana’s program on 02/12/2019 at 0:30 it will appear the mouse program and not Liana.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.