How to use time_format() in Mysql?

Asked

Viewed 96 times

1

I made a table like this:

create table tabela (
hora time not null
);

This table returns me hour, minute and second. How is the table with time_format()? I want to leave it with the time and the second. My doubt is in the syntax (way to assemble the team).

Value returned: 00:00:00. Value I want you to return: 00:00.

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

  • Same time and second? or would be hour and minute?

  • I only want the hour and the minute.

1 answer

3

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

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

By way of doubt, also follows how to display hour and minutes:

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

I put in the Sqlfiddle for future reference

  • 1

    I doubt it is Hour:Second :)

  • 1

    I also think, I put the two formats to ensure

  • But I don’t want to select it, I want the syntax when it is created in the table.

  • @Willbill, I’m sorry, it wasn’t clear what your question was about setting the table, the guy time it’s time, minute and second

  • @Barbetta, that is, I want the team to be only hour and minute. I do not want in select, but when creating the team in the table.

  • from what I understand you want the table to be only hour and minute(00:00), the first moment, what comes to mind is to save the field as varchar.

  • But is there no way to take the seconds at the time of creation?

  • I did a quick search here and found nothing indicating that it is possible to do this, maybe this link and this other link can help you

Show 3 more comments

Browser other questions tagged

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