How to use the MySQL date data type datetime
This article will explain in detail how to use the MySQL date data type datetime. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
MySQL date data type datetime.
Datetime type: can be used for values that need to contain both date and time information. (recommended study: MySQL video tutorial)
Datetime:MySQL retrieves and displays DATETIME types in 'YYYY-MM-DD HH:mm:ss' format.
Types
Size (byte) range format usage DATETIME
eight
1000-01-01 0012-31 23:59:59
YYYY-MM-DD HH:MM:SS
Mixed date and time valu
When you create a table in MySQL, you can easily choose the right data type through type introduction. However, it may be a little difficult to choose datetime or timestamp. These two date-time types have their own advantages: datetime has a larger date range, and timestamp takes up less storage space, which is only half that of datetime.
In addition, timestamp type columns have a feature: by default, when insert, update data, the timestamp column is automatically populated / updated at the current time (CURRENT_TIMESTAMP). "automatic" means that if you leave it alone, MySQL will handle it for you.
The code for creating the table is:
Create table T8 (`id1` timestamp NOT NULL default CURRENT_TIMESTAMP, `id2` datetime default NULL)
In general, I prefer to use the datetime date type.
The comparison between the two:
1. Timestamp easily supports a smaller range than timedate. And it is easy to go beyond.
2.timestamp is influenced by time zone timezone, MYSQL version and server SQL MODE.
On the use of MySQL date data type datetime to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.