Skip seconds in the MySQL time field

4

I have a field in my table of type time , where I save my time. The problem is that it is saving like this: 10:30:01 , how do I save it just the hour and minutes. That is without the seconds?

The field is thus in BD hora time DEFAULT NULL

    
asked by anonymous 29.07.2016 / 15:27

2 answers

6

Just like rray said, you have the following options DATE_FORMAT and TIME_FORMAT :

DATE_FORMAT(NOW(), "%H:%i");

TIME_FORMAT(NOW(), "%H:%i");

I believe that for your case, TIME_FORMAT is more indicated:

SELECT *, TIME_FORMAT(hora_entrega, "%H:%i") as hora_entrega FROM pedidos
    
29.07.2016 / 15:54
8

You can do hour comparisons and presentations using the date_format() function of MySQL to delete the seconds. H represents the time in 0-23 format and i minutes. Even if the seconds are omitted in the insert the field is written with 00 seconds.

Example:

SELECT date_format('%H:%i', now())

List of arguments accepted by date_format

    
29.07.2016 / 15:52