DATE
DATE
type is used to represent a date, including three parts: year, month, and day, but does not include time zone information. This type is very useful when dealing with data that is not related to time, such as recording a user's birth date or the date an event occurred.
Syntax
year
: Year, formatted as a four-digit number, such as 2023.month
: Month, formatted as a two-digit number, ranging from 01 to 12, such as 03.day
: Day, formatted as a two-digit number, ranging from 01 to 31 depending on the month, such as 15.
Example
- Insert the current date:
- Calculate the difference between two dates:
- Convert the string to a date and compare:
Notes
- When the input month or date is out of the actual range, an error will be returned.
- When performing date calculations, pay attention to the legality of the result to avoid non-existent dates (e.g., 2023-02-30).