DATETIME and TIMESTAMP Length/Values Error(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)]
文档:
- DATE、DATETIME 和 TIMESTAMP 类型莉>
- 日期和时间类型概述
这篇关于DATETIME 和 TIMESTAMP 长度/值错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:DATETIME 和 TIMESTAMP 长度/值错误
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- SQL 临时表问题 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
