简体   繁体   English

如何使用php将日期正确插入MYSQL数据库?

[英]How to properly insert date into MYSQL database using php?

I want to store and display date in this format "1.1.1990", (dmY) 我想以这种格式存储和显示日期“1.1.1990”,(dmY)

I've got a date column in my database with these settings 我的数据库中有一个使用这些设置的日期列

TYPE: DATE 类型:日期

Browser display transformation: Date Format(text/plain: Dateformat) 浏览器显示转换:日期格式(text / plain:Dateformat)

Browser display transformation options: 0,'%j.%n.%Y','local' 浏览器显示转换选项:0,'%j。%n。%Y','本地'

My query goes as : 我的查询如下:

INSERT INTO table VALUES(STR_TO_DATE('1.1.1990', '%e.%c.%Y')) INSERT INTO表VALUES(STR_TO_DATE('1.1.1990','%e。%c。%Y'))

So far the query is accepted but a blank field is displayed in database 到目前为止,查询已被接受,但数据库中显示一个空白字段

Only other thing i could get is without using STR_TO_DATE to add a default date as 1.1.1970 只有我能得到的其他东西是没有使用STR_TO_DATE将默认日期添加为1.1.1970

  1. You have to set the column in date type 您必须在日期类型中设置列
  2. You can ensure the date is wellformed: select STR_TO_DATE('1.1.1990', '%e.%c.%Y'); 您可以确保日期良好: select STR_TO_DATE('1.1.1990', '%e.%c.%Y');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM