How to use time_format () in MySQL?

1

I made a table like this:

create table tabela (
hora time not null
);

This table returns me hour, minute, and second. How does the table with time_format ()? I want to leave you alone with the hour and the second. My question is in the syntax (way to set up the team).

Return Value: 00:00:00. Value that I want to return: 00:00.

Reason: I'm capturing the time of an HTML form (00:00) and saving in the database. When the time is sent from the form to the database, the database stores it as follows: 00:00:00. That's why I want the team to accept this format when the table is created: 00:00.

    
asked by anonymous 02.05.2018 / 16:17

1 answer

3

The time_format() first receives the field and then the formatting parameters, to display time and second would look like this:

select TIME_FORMAT(hora, '%H:%s') from tabela

Just in case, here's how to display hour and minutes:

select TIME_FORMAT(hora, '%H:%i') from tabela

I put it in SQLFiddle for future reference

    
02.05.2018 / 16:35