In This Article, You Will Know About SQL Working With Dates.
Before moving ahead, let’s know a bit about the SQL CREATE INDEX Statement.
Table of Contents
Note: Your database date formate should be matched with the date formate you are inserting.
SQL Date Data Types
Here’s the following MySQL command for inserting a date or date/time –
DATE – format YYYY-MM-DD
DATETIME – format: YYYY-MM-DD HH:MI:SS
TIMESTAMP – format: YYYY-MM-DD HH:MI:SS
YEAR – format YYYY or YY
Here’s the following SQL command for inserting a date or date/time –
DATE – format YYYY-MM-DD
DATETIME – format: YYYY-MM-DD HH:MI:SS
SMALLDATETIME – format: YYYY-MM-DD HH:MI:SS
TIMESTAMP – format: a unique number
Note: Choose the data type for the column when the new table is created.
SQL Date
Table: Movie
Serial_Number | Movie_Name | Release_Date |
1 | Avatar | 10-11-1987 |
2 | Titanic | 25-12-1999 |
3 | Avengers | 30-10-2010 |
4 | Notebook | 29-08-2019 |
Example: Return the release date of the movie “Titanic” from the whole table.
SELECT *
FROM Movie
WHERE Release_Date = '25-12-1999';
Example: Return the release date of the movie “Titanic” from the column “Release_Date”.
SELECT Release_Date
FROM Movie
WHERE Release_Date = '25-12-1999';
Serial_Number | Movie_Name | Release_Date |
1 | Avatar | 10-11-1987 10:00:00 |
2 | Titanic | 25-12-1999 11:02:15 |
3 | Avengers | 30-10-2010 12:16:38 |
4 | Notebook | 29-08-2019 08:12:12 |
Example: Return the release date of the movie “Titanic” from the whole table.
SELECT * FROM Movie
WHERE Release_Date = '25-12-1999';
As a result, it will not return any answer because the SQL query is only looking for data not for time too but in the above table, time is also mentioned.
If you find anything incorrect in the above-discussed topic and have further questions, please comment below.
Connect on: