An explanation of the knowledge about the SQL Date function

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.