Using MySQL time type

MySQL is a widely used relational database management system that provides rich time types when processing date and time data. These time types allow developers to store, manipulate, and query time-related data.

In MySQL, there are mainly the following time types:

  1. DATE: Used to store date values ​​in the format 'YYYY-MM-DD'. For example, '2023-09-24' means September 24, 2023.

  2. TIME: Used to store time values ​​in the format 'HH:MM:SS'. For example, '15:30:45' means 3:30 minutes and 45 seconds in the afternoon.

  3. DATETIME: Used to store date and time values ​​in the format 'YYYY-MM-DD HH:MM:SS'. For example, '2023-09-24 15:30:45' means 3:30 minutes and 45 seconds on September 24, 2023.

  4. TIMESTAMP: used to store date and time values ​​in the same format as DATETIME. However, the TIMESTAMP type will automatically assign the current time to the field when inserting data, which can be used to record the creation or modification time of the data.

  5. YEAR: Used to store year values ​​in the format of 'YYYY'. For example, '2023' means the year 2023.

Here is some sample code using the MySQL time type:

Create a table with a time field:

CREATE TABLE my_table (
    id INT 

Guess you like

Origin blog.csdn.net/m0_47037246/article/details/133532481