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

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

问题描述

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

I was using int type for storing date/time. 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 as I could start from beginning.

错误图片

推荐答案

定义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));

创建表语法的摘要:

Abstract from CREATE TABLE Syntax:

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

文档:

  • The DATE, DATETIME, and TIMESTAMP Types
  • Date and Time Type Overview

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

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