SQL DateFunctionis very important in the use of php, so this article will explain it.
SQL Date
When we deal with dates, the most difficult task is probably to ensure that the format of the inserted date matches the format of the date column in the database.
As long as the data contains only the date part, there will be no problem running thequery. However, when time is involved, things get a little more complicated.
Before discussing the complexity of date queries, let's first take a look at the most important built-in date processing functions.
SQL DateData Types
MySQLUse the following data types to store dates or dates in the database/ Time value:
DATE - Format YYYY-MM-DD
DATETIME- Format: YYYY-MM-DD HH:MM:SS
TIMESTAMP - Format: YYYY-MM-DD HH:MM:SS
YEAR - Format YYYY or YY
SQL Server uses the following data types to store date or date/time values in the database:
DATE - Format YYYY-MM-DD
DATETIME - Format: YYYY-MM-DD HH:MM:SS
SMALLDATETIME - Format: YYYY-MM-DD HH: MM:SS
TIMESTAMP - Format: Unique Number
SQL Date Processing
If the time part is not involved, then we can easily compare two dates!
Now, we want to select the records whose OrderDate is "2008-12-26" from the above table.
We use the following SELECT statement:
SELECT * FROM Orders WHERE OrderDate='2008-12-26'
This article is related to the SQL Date function Explanation, for more learning materials, please pay attention to the php Chinese website to view.
Related recommendations:
Explanation on SQL VIEW (view) related knowledge
About SQL AUTO INCREMENT field related Explain
#Related operations of SQL ALTER TABLE statement
The above is the detailed content of Explanation of knowledge related to SQL Date function. For more information, please follow other related articles on the PHP Chinese website!