Calculate time interval in SQL

Asked

Viewed 75 times

0

I have a table where I have 2 fields horainicio and horaafinal I’m wanting to get the results that fits between the initial and final values but unsuccessfully follow what I’m using.

inserir a descrição da imagem aqui

I’m taking the current time and trying to make this comparison

$horaatual = date("H:i");

  SELECT * FROM programacao WHERE horafinal => '$horaatual' ORDER BY Nid DESC LIMIT 1";

any suggestions? changed the code

  • 1

    In what format is the horainicio field?

  • Already tried ?

  • the field is empty where it is registered as follows in text 11:15 , 15:25 etc

  • Do you register one hour for records? or several hours in the same?

  • registration by registration and a system of programming of talkers EX: ID 1 name= so-called time=12:00 ID2 name=Ciclano time=15:00

  • @Marconi now tried to Utulizar the betwenn however did not return results

  • @Arsomnolasco here has a question well self Explanatory. Could you edit one and put in the similar model? I say structure, data and expected results

  • 1

    Already tried to convert the field varchar for team using the hour() ?'{$horaatual}' BETWEEN HOUR(horainicio) AND HOUR(horafinal) ?

  • @Arsomnolasco has succeeded?

  • no results either

  • Have you considered changing your fields to a date type? It’s much easier to work with.

Show 6 more comments

1 answer

0

Your initial query is written with errors. The correct one would be >= and not =>. The field in which it contains the values of the times must be of the TIME type. Once that’s done, I see no reason why your code should not work.

Browser other questions tagged

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