如何修复MySQL数据库中的日期 [英] How to fix the date in a MySQL db

查看:94
本文介绍了如何修复MySQL数据库中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

在我的MySQL数据库中,人们必须填写的其中一个字段是DOB

(出生日期)。

我现在已经设法通过表单开始将数据插入我的数据库,DOB字段的数据类型为DATE,但每次我添加数据并且

然后检查我的数据库,我看到DOB显示为0000-00-00。

有没有人知道我怎么能把它做对了? br />

TIA,

Newsscanner。

Hello,

In my MySQL database, one of the fields eople have to fill in is "DOB"
(Date of Birth).
I have now managed to begin inserting data into my DB via a form, the
data type for the DOB field is "DATE", but every time I add data and
then check my db, I see the DOB displayed as "0000-00-00".
Has anyone got any idea how I could put this right?

TIA,
Newsscanner.

推荐答案

Newsscanner写道:
Newsscanner wrote:
我现在已经设法通过表单开始将数据插入我的数据库,DOB字段的数据类型是DATE,但每次我添加数据和有谁知道我怎么能把它放好?
I have now managed to begin inserting data into my DB via a form, the
data type for the DOB field is "DATE", but every time I add data and
then check my db, I see the DOB displayed as "0000-00-00".
Has anyone got any idea how I could put this right?




您能提供用于插入数据的SQL查询吗?如果没有

它,就不可能分辨出你做错了什么,但是总是

错误是:


#有时用户忘记在值周围添加''''

插入表(DOB)值(2005-08-16); #Wrong

插入表格(DOB)值(''2005-08-16''); #Crrect


#有时日期的格式错误。使用yyyy-mm-dd格式

插入表(DOB)值(''8/16/2005''); #Wrong

插入表格(DOB)值(''2005-08-16''); #正确


#编程语言也会发生错误

#并且变量的值为空

insert into table(DOB)值(''''); #Wrong

插入表格(DOB)值(''2005-08-16''); #Correct



Can you provide the SQL query you are using to insert the data? Without
it, it is impossible to tell what you are doing wrong, but commong
mistakes are:

# Sometimes user forgets to add '''' around the value
insert into table(DOB) values( 2005-08-16 ); # Wrong
insert into table(DOB) values( ''2005-08-16'' ); # Correct

# Sometimes the date is given in wrong format. Use yyyy-mm-dd format
insert into table(DOB) values( ''8/16/2005'' ); # Wrong
insert into table(DOB) values( ''2005-08-16'' ); # Correct

# Comming error also happens with the programming language
# and the value of the variable is empty
insert into table(DOB) values( '''' ); # Wrong
insert into table(DOB) values( ''2005-08-16'' ); # Correct


Aggro写道:
Newsscanner写道:
Newsscanner wrote:
我现在设法开始插入通过表单将数据存入我的数据库,DOB字段的数据类型为DATE,但每次我添加数据然后检查我的数据库,我看到DOB显示为0000 -00-00。
有谁知道我怎么能把这个放到正确的位置?
I have now managed to begin inserting data into my DB via a form, the
data type for the DOB field is "DATE", but every time I add data and
then check my db, I see the DOB displayed as "0000-00-00".
Has anyone got any idea how I could put this right?



你能提供用于插入数据的SQL查询吗?如果没有它,就不可能分辨出你做错了什么,但是错误是错误的:

#有时用户会忘记在值周围添加'''' /> insert into table(DOB)values(2005-08-16); #Wrong
插入表格(DOB)值(''2005-08-16''); #Correct

#有时日期的格式错误。使用yyyy-mm-dd格式
插入表(DOB)值(''8/16/2005''); #Wrong
插入表格(DOB)值(''2005-08-16''); #CORrect

#编程语言也会发生错误
#并且变量的值为空
插入表(DOB)值(''''); #Wrong
插入表格(DOB)值(''2005-08-16''); #Correct


Can you provide the SQL query you are using to insert the data? Without
it, it is impossible to tell what you are doing wrong, but commong
mistakes are:

# Sometimes user forgets to add '''' around the value
insert into table(DOB) values( 2005-08-16 ); # Wrong
insert into table(DOB) values( ''2005-08-16'' ); # Correct

# Sometimes the date is given in wrong format. Use yyyy-mm-dd format
insert into table(DOB) values( ''8/16/2005'' ); # Wrong
insert into table(DOB) values( ''2005-08-16'' ); # Correct

# Comming error also happens with the programming language
# and the value of the variable is empty
insert into table(DOB) values( '''' ); # Wrong
insert into table(DOB) values( ''2005-08-16'' ); # Correct



好​​的,谢谢。

但由于输入来自用户,我认为它会显示

无论有什么已输入。

我的查询如下所示:

"


OK, thanks.
But since the input comes from the user, I thought it would display
whatever has been typed in.
My query looks like this:
"


DOB =


这篇关于如何修复MySQL数据库中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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