How to write date in mysql

下次还敢
Release: 2024-04-22 19:57:38
Original
355 people have browsed it

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)

How to write date in mysql

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
Copy after login

For example:

2023-03-08 -- 表示 2023 年 3 月 8 日
Copy after login

Date time format:

YYYY-MM-DD HH:MM:SS
Copy after login

For example:

2023-03-08 12:30:15 -- 表示 2023 年 3 月 8 日 12:30:15
Copy after login

UNIX timestamp:

MySQL also supports storing UNIX timestamps, which represent the elapsed time since Epoch seconds.

FROM_UNIXTIME(unix_timestamp)
Copy after login

For example:

FROM_UNIXTIME(1678339215) -- 表示 2023 年 3 月 8 日 12:30:15
Copy after login

String format:

STR_TO_DATE(string_value, format)
Copy after login

whereformatspecifies the format of the string. For example:

STR_TO_DATE('03/08/2023', '%m/%d/%Y') -- 表示 2023 年 3 月 8 日
Copy after login

Note:

  • The date part must be in the format of YYYY-MM-DD.
  • The time part can be omitted, if omitted, the default is 00:00:00.
  • UNIX timestamp cannot be negative.
  • 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!