使用MYSQL将h:mm pm/am时间格式插入数据库 [英] Insert h:mm pm/am time format into database using MYSQL

查看:151
本文介绍了使用MYSQL将h:mm pm/am时间格式插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将以h:mm am/pm格式编写的时间插入存储为标准DATETIME格式(hh:mm:ss)的数据库中,但是我不知道如何转换发布的时间转换为标准格式,以便数据库将其接受.

I'm trying to insert a time written in h:mm am/pm format into a database that is stored as standard DATETIME format ( hh:mm:ss ) but I can't figure out how to convert the posted time into standard format so the database will accept it.

这是我到目前为止一直在尝试的事情:

This is what I've been trying so far:

$title = $_POST['inputTitle'];
$date = $_POST['inputDate'];
$time = date('h:i:s a', strtotime($_POST['inputTime']));
$desc = $_POST['inputDesc'];


//msql query to insert data
$query = "INSERT INTO events(title, date, time, description) VALUES ('$title','$date','$time','$desc')";

但这不起作用(时间仍然无法提交)任何想法吗?

but this doesn't work(time still won't submit) any ideas?

推荐答案

您应该使用TIME类型而不是DATETIME类型.

You should use TIME type not DATETIME type.

DATETIME格式为:yyyy-mm-dd hh:ii:ss

DATETIME格式

TIME格式为:hh:ii:ss

时间格式

这篇关于使用MYSQL将h:mm pm/am时间格式插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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