Mysql如何将时间数据类型设置为在数据库中只有HH:MM [英] Mysql how to set time data type to be only HH:MM in database

查看:844
本文介绍了Mysql如何将时间数据类型设置为在数据库中只有HH:MM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何设置我的mysql数据库字段时间数据类型只有HH:MM在数据库中,在我的脚本用户只输入HH:MM和DB自动添加最后:SS数字,问题是当我拉该值编辑,它添加了最后的数字,这是一个恼人的,我可以摆脱它与PHP和截断结束,但我希望一种方式设置它在DB中删除

$ p

解决方案

我不相信你可以配置你的数据库来存储没有SS的时间。
MySQL的TIME DataType参考: http://dev.mysql .com / doc / refman / 5.1 / en / time.html



您必须在mysql查询中将格式设置为HH:MM

在PHP中:

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

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



在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 p>

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 digits 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

这篇关于Mysql如何将时间数据类型设置为在数据库中只有HH:MM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆