Grab Mysql database time

Asked

Viewed 155 times

0

-Good night, you guys!

I have an application that takes data from the database and displays it on the screen. It’s a television schedule, I mean, it shows what’s going on live and what’s going on afterwards.

The type of data representing the time of programming is Datetime

I would like to take only the hour and the minute, ignoring the date. Example: in the bank is like this (2019-08-31 20:50) I want to take only the 20:50 and show on screen. I’m doing with php.

How can I do that?

My current code:

<?php
//SELECT
$gh_resultado = $wpdb->get_results("SELECT * FROM Programacao where horario >= '$gh_data' order by horario");

//Mostrando na tela
echo $gh_resultado[0]->horario;
?>
  • Use the Mysql TIME(your_field_datetime) function.

1 answer

0


As explained above only use mysql TIME() function Example.:

SELECT *, TIME(horario) AS horario FROM Programacao where horario >= '$gh_data' order by horario

Remembering that the name of the property to be returned will change to TIME(property), so it is important to rename it again to its old name as

TIME(horario) AS horario
  • It worked! Thank you so much for your help!!!!

Browser other questions tagged

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