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 长度/值错误
基础教程推荐
- oracle区分大小写的原因? 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 在多列上分布任意行 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
