开发者

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

how can I set my mysql database field "time" data type to only be HH:MM in the database, in my script the user only enters HH:MM and the DB automatically adds the last :SS digits, the problem is when I pull that value to edit, it adds the last d开发者_StackOverflow社区igits also, which is kind of annoying, I can get rid of it with PHP and truncating off the end, but I was hoping for a way to set it in the DB to remove those last 2 SS digits for good.


I don't believe you can configure your database to store the time without the SS. MySQL's TIME DataType reference: http://dev.mysql.com/doc/refman/5.1/en/time.html

You'll have 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


use TIME_FORMAT(time,format) function of mysql

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜