在MySQL中插入datetime时的PHP date()格式 [英] PHP date() format when inserting into datetime in MySQL

查看:86
本文介绍了在MySQL中插入datetime时的PHP date()格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想将结果插入MySQL datetime type列中,传递给PHP date()函数的正确格式是什么?

What is the correct format to pass to the date() function in PHP if I want to insert the result into a MySQL datetime type column?

我一直在尝试date("Y-M-D G:i:s"),但是每次都只插入"0000-00-00 00:00:00".

I've been trying date("Y-M-D G:i:s") but that just inserts "0000-00-00 00:00:00" everytime.

推荐答案

问题是您使用的是文本表示形式的'M''D',MySQL期望格式为

The problem is that you're using 'M' and 'D', which are a textual representations, MySQL is expecting a numeric representation of the format 2010-02-06 19:30:13

尝试:date("Y-m-d H:i:s")使用等效的数字.

Try: date("Y-m-d H:i:s") which uses the numeric equivalents.

G切换为H,虽然可能没有影响,但您可能希望使用前导0的24小时制.

edit: switched G to H, though it may not have impact, you probably want to use 24-hour format with leading 0s.

这篇关于在MySQL中插入datetime时的PHP date()格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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