Rechercher dans le manuel MySQL
11.2.1 Date and Time Data Type Syntax
The date and time data types for representing temporal values
are DATE
,
TIME
,
DATETIME
,
TIMESTAMP
, and
YEAR
.
For the DATE
and
DATETIME
range descriptions,
“supported” means that although earlier values
might work, there is no guarantee.
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
,
where type_name
(fsp
)type_name
is
TIME
,
DATETIME
, or
TIMESTAMP
, and
fsp
is the fractional seconds
precision. For example:
The fsp
value, if given, must be in
the range 0 to 6. A value of 0 signifies that there is no
fractional part. If omitted, the default precision is 0. (This
differs from the standard SQL default of 6, for compatibility
with previous MySQL versions.)
Any TIMESTAMP
or
DATETIME
column in a table can
have automatic initialization and updating properties; see
Section 11.2.5, “Automatic Initialization and Updating for TIMESTAMP and DATETIME”.
A date. The supported range is
'1000-01-01'
to'9999-12-31'
. MySQL displaysDATE
values in'
format, but permits assignment of values toYYYY-MM-DD
'DATE
columns using either strings or numbers.A date and time combination. The supported range is
'1000-01-01 00:00:00.000000'
to'9999-12-31 23:59:59.999999'
. MySQL displaysDATETIME
values in'
format, but permits assignment of values toYYYY-MM-DD hh:mm:ss
[.fraction
]'DATETIME
columns using either strings or numbers.An optional
fsp
value in the range from 0 to 6 may be given to specify fractional seconds precision. A value of 0 signifies that there is no fractional part. If omitted, the default precision is 0.Automatic initialization and updating to the current date and time for
DATETIME
columns can be specified usingDEFAULT
andON UPDATE
column definition clauses, as described in Section 11.2.5, “Automatic Initialization and Updating for TIMESTAMP and DATETIME”.A timestamp. The range is
'1970-01-01 00:00:01.000000'
UTC to'2038-01-19 03:14:07.999999'
UTC.TIMESTAMP
values are stored as the number of seconds since the epoch ('1970-01-01 00:00:00'
UTC). ATIMESTAMP
cannot represent the value'1970-01-01 00:00:00'
because that is equivalent to 0 seconds from the epoch and the value 0 is reserved for representing'0000-00-00 00:00:00'
, the “zero”TIMESTAMP
value.An optional
fsp
value in the range from 0 to 6 may be given to specify fractional seconds precision. A value of 0 signifies that there is no fractional part. If omitted, the default precision is 0.The way the server handles
TIMESTAMP
definitions depends on the value of theexplicit_defaults_for_timestamp
system variable (see Section 5.1.8, “Server System Variables”).If
explicit_defaults_for_timestamp
is enabled, there is no automatic assignment of theDEFAULT CURRENT_TIMESTAMP
orON UPDATE CURRENT_TIMESTAMP
attributes to anyTIMESTAMP
column. They must be included explicitly in the column definition. Also, anyTIMESTAMP
not explicitly declared asNOT NULL
permitsNULL
values.If
explicit_defaults_for_timestamp
is disabled, the server handlesTIMESTAMP
as follows:Unless specified otherwise, the first
TIMESTAMP
column in a table is defined to be automatically set to the date and time of the most recent modification if not explicitly assigned a value. This makesTIMESTAMP
useful for recording the timestamp of anINSERT
orUPDATE
operation. You can also set anyTIMESTAMP
column to the current date and time by assigning it aNULL
value, unless it has been defined with theNULL
attribute to permitNULL
values.Automatic initialization and updating to the current date and time can be specified using
DEFAULT CURRENT_TIMESTAMP
andON UPDATE CURRENT_TIMESTAMP
column definition clauses. By default, the firstTIMESTAMP
column has these properties, as previously noted. However, anyTIMESTAMP
column in a table can be defined to have these properties.A time. The range is
'-838:59:59.000000'
to'838:59:59.000000'
. MySQL displaysTIME
values in'
format, but permits assignment of values tohh:mm:ss
[.fraction
]'TIME
columns using either strings or numbers.An optional
fsp
value in the range from 0 to 6 may be given to specify fractional seconds precision. A value of 0 signifies that there is no fractional part. If omitted, the default precision is 0.A year in 4-digit format. MySQL displays
YEAR
values inYYYY
format, but permits assignment of values toYEAR
columns using either strings or numbers. Values display as1901
to2155
, or0000
.For additional information about
YEAR
display format and interpretation of input values, see Section 11.2.4, “The YEAR Type”.NoteAs of MySQL 8.0.19, the
YEAR(4)
data type with an explicit display width is deprecated and support for it will be removed in a future MySQL version. Instead, useYEAR
without a display width, which has the same meaning.MySQL 8.0 does not support the 2-digit
YEAR(2)
data type permitted in older versions of MySQL. For instructions on converting to 4-digitYEAR
, see 2-Digit YEAR(2) Limitations and Migrating to 4-Digit YEAR in MySQL 5.7 Reference Manual.
The SUM()
and
AVG()
aggregate functions do not
work with temporal values. (They convert the values to numbers,
losing everything after the first nonnumeric character.) To work
around this problem, convert to numeric units, perform the
aggregate operation, and convert back to a temporal value.
Examples:
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 26/06/2006, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/mysql-rf-date-and-time-type-syntax.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.