Question: What are the formats for writing dates in MySQL? Answer: Standard SQL format: YYYY-MM-DD Date and time format: YYYY-MM-DD HH:MM:SSUNIX Timestamp: FROM_UNIXTIME(unix_timestamp) String format: STR_TO_DATE(string_value, format)
MySQL date writing format
In MySQL, the date type is used to store date and time information. When writing dates, you can use the following format:
Standard SQL format:
YYYY-MM-DD
For example:
2023-03-08 -- 表示 2023 年 3 月 8 日
Date time format:
YYYY-MM-DD HH:MM:SS
For example:
2023-03-08 12:30:15 -- 表示 2023 年 3 月 8 日 12:30:15
UNIX timestamp:
MySQL also supports storing UNIX timestamps, which represent the elapsed time since Epoch seconds.
FROM_UNIXTIME(unix_timestamp)
For example:
FROM_UNIXTIME(1678339215) -- 表示 2023 年 3 月 8 日 12:30:15
String format:
STR_TO_DATE(string_value, format)
whereformat
specifies the format of the string. For example:
STR_TO_DATE('03/08/2023', '%m/%d/%Y') -- 表示 2023 年 3 月 8 日
Note:
STR_TO_DATE()
The function must specify the correct format, otherwise an error will occur.The above is the detailed content of How to write date in mysql. For more information, please follow other related articles on the PHP Chinese website!