The SQL Date function is important in the use of PHP, so this article will explain it.
SQL Date
When we work on dates, the hardest task is to ensure that the date you insert is formatted to match the format of the date column in the database.
As long as the data contains only the date parts, running the query will not be a problem. However, if time is involved, the situation is a little more complicated.
Before we discuss the complexity of the date query, let's look at the most important built-in date processing functions.
SQL Date Data type
MySQL stores date or date/time values in the database using the following data types:
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 a record from the table above that OrderDate is "2008-12-26".
We use the following SELECT statement:
SELECT * from Orders WHERE orderdate= ' 2008-12-26 '
This article is related to the SQL Date function, more learning materials to focus on the PHP Chinese network can be viewed.