DATETIME 和 TIMESTAMP 长度/值错误 [英] DATETIME and TIMESTAMP Length/Values Error

查看:20
本文介绍了DATETIME 和 TIMESTAMP 长度/值错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 int 类型来存储日期时间类型的数据.为了方便从 MySQL 获取特定范围内的数据,我尝试将其更改为 TIMESTAMP/DATETIME 但它给出了与 附加图像 在这两种情况下.数据类型 TIMESTAMP/DATETIME 的格式为 YYYY-MM-DD HH:MM:SS,长度为 19 个字符.

I was using int type for storing datetime type data. For the convenience of getting the data in specific range from MySQL, I tried changing it to TIMESTAMP/DATETIME but it is giving the error as in the attached image in both the cases. The format for datatype TIMESTAMP/DATETIME is YYYY-MM-DD HH:MM:SS which is 19 character long.

我找不到合适的教程/文章来了解有关此错误/问题的知识.

I could not get a proper tutorial/article to get knowledge about this error/issue.

错误图片

推荐答案

定义 DATETIME 或 TIMESTAMP 字段时,无需指定长度.

When defining a DATETIME or TIMESTAMP field, there's no need to specify the length.

这是错误消息所指的内容:

This is what the error message refers to:

DATETIME 或 TIMESTAMP 值可以包含尾随小数秒部分,精度最高可达微秒(6 位)

A DATETIME or TIMESTAMP value can include a trailing fractional seconds part in up to microseconds (6 digits) precision

MySQL 允许 TIME、DATETIME 和 TIMESTAMP 值使用小数秒,精度最高为微秒(6 位).要定义包含小数秒部分的列,请使用语法 type_name(fsp),其中 type_name 是 TIME、DATETIME 或 TIMESTAMP,fsp 是小数秒精度.例如:

MySQL permits fractional seconds for TIME, DATETIME, and TIMESTAMP values, with up to microseconds (6 digits) precision. To define a column that includes a fractional seconds part, use the syntax type_name(fsp), where type_name is TIME, DATETIME, or TIMESTAMP, and fsp is the fractional seconds precision. For example:

CREATE TABLE t1 (t TIME(3), dt DATETIME(6));

摘自CREATE TABLE语法:>

| TIME[(fsp)]
| TIMESTAMP[(fsp)]
| DATETIME[(fsp)]

文档:

这篇关于DATETIME 和 TIMESTAMP 长度/值错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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