mysql将字符串转换为时间格式来自数据库的wheb查询

时间:2015-12-02 03:53:29

标签: php mysql sql

将字段存储时间设置为varchar EX:06:30 AM。我需要从此字段中选择一个查询并转换为数字6.30

2 个答案:

答案 0 :(得分:0)

使用date

转换字符串
echo date('g.i',strtotime('06:30 AM'));

输出6.30

g => 12-hour format of an hour without leading zeros    1 through 12
i => Minutes with leading zeros 00 to 59

答案 1 :(得分:0)

将<{1}}用于此

TIME_FORMAT()

修改

SELECT TIME_FORMAT( column_name, '%H.%i' ) AS time from table_name;