Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the ​ MySQL date data type datetime

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report