Date and Time Types
Table 1 lists the date and time types that can be used in M-compatible databases.
|
Name |
Description |
Storage Space |
|---|---|---|
|
DATE |
Used to store year, month, and day information, that is, date information.
|
4 bytes |
|
TIME[(p)] |
Used to store hour, minute, second, and millisecond information, that is, time information.
|
8 bytes |
|
DATETIME[(p)] |
Used to store year, month, and day information, that is, date information.
|
8 bytes |
|
TIMESTAMP[(p)] |
Used to store data that contains both date and time information. Values are affected by the database time zone.
|
8 bytes |
|
YEAR |
Used to store year information.
|
4 bytes |
- M compatibility does not support the following ODBC syntax literals:
{ t 'str' }
{ ts 'str' }
- M compatibility supports the following standard SQL literals:
TIME 'str'
TIMESTAMP'str'
- The data of the time type automatically ignores all zeros at the end of the data when it is displayed.
- In strings with separators, the backslash (\) is regarded as a common punctuation character instead of an escape character in the M-compatible database.
- The default value of p is 0.
- If the value of sql_mode contains strict_trans_tables and the input value is invalid or out of the value range, an error is reported. If strict_trans_tables is not contained and the input value is invalid or out of the value range, 0 is stored.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
-- Create a table. m_db=# CREATE TABLE temporal_date(a DATE); m_db=# CREATE TABLE temporal_time(b TIME); m_db=# CREATE TABLE temporal_datetime(c DATETIME(5)); m_db=# CREATE TABLE temporal_timestamp(d TIMESTAMP); m_db=# CREATE TABLE temporal_year(e YEAR); -- Insert data. m_db=# INSERT INTO temporal_date VALUES ('2020-02-02'); m_db=# INSERT INTO temporal_date VALUES (date'2020-02-02'); m_db=# INSERT INTO temporal_date VALUES (20200202); m_db=# INSERT INTO temporal_time VALUES ('20 10:00:00'); m_db=# INSERT INTO temporal_time VALUES ('800:00:00'); m_db=# INSERT INTO temporal_time VALUES (time'200:00:00'); m_db=# INSERT INTO temporal_datetime VALUES ('2020-02-02T04:04:04'); m_db=# INSERT INTO temporal_datetime VALUES (timestamp'2020-02-02 10:00:00'); m_db=# INSERT INTO temporal_datetime VALUES (20201010010101); m_db=# INSERT INTO temporal_timestamp VALUES ('2020-02-02 10:00:00'); m_db=# INSERT INTO temporal_timestamp VALUES (20200220101010); m_db=# INSERT INTO temporal_year VALUES (2020); m_db=# INSERT INTO temporal_year VALUES (20); -- View data. m_db=# SELECT * FROM temporal_date; a ------------ 2020-02-02 2020-02-02 2020-02-02 (3 rows) m_db=# SELECT * FROM temporal_time; b ----------- 490:00:00 800:00:00 200:00:00 (3 rows) m_db=# SELECT * FROM temporal_datetime; c --------------------------- 2020-02-02 04:04:04.00000 2020-02-02 10:00:00.00000 2020-10-10 01:01:01.00000 (3 rows) m_db=# SELECT * FROM temporal_timestamp; d --------------------- 2020-02-02 10:00:00 2020-02-20 10:10:10 (2 rows) m_db=# SELECT * FROM temporal_year; e ------ 2020 2020 (2 rows) -- Drop the table. m_db=# DROP TABLE temporal_date; m_db=# DROP TABLE temporal_time; m_db=# DROP TABLE temporal_datetime; m_db=# DROP TABLE temporal_timestamp; m_db=# DROP TABLE temporal_year; |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot