Mysql how to set time type data only HH: MM in database

how can I set my mysql database β€œtime” data type only in HH: MM in the database, in my script the user enters only HH: MM, and the DB automatically adds the last: SS digits, the problem is when I pull this value for editing, it also adds the last digits, which is annoying, I can get rid of it with PHP and truncate from the end, but I was hoping that you set it in the database to delete the last 2 digits of SS permanently.

+5
source share
2 answers

I do not believe that you can set up your database to store time without SS. MySQL TIME DataType Link: http://dev.mysql.com/doc/refman/5.1/en/time.html

You will need to set the formatting to HH: MM either in the mysql query or in php after you pull the data.

In PHP:

$date = date('H:i', strtotime($db_date_value));

http://us3.php.net/manual/en/function.date.php

In MySQL:

DATE_FORMAT(date_created, "%H:%i") as date_created

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

+4
source

use TIME_FORMAT(time,format)mysql function

0
source

All Articles