bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL Database
SQL•SQL Database

SQL Working With Dates

SQL Dates

The most difficult part when working with dates in databases, is to be sure that the format of the date you are trying to insert/select, matches the format of the date column in the database.

SQL Date Data Types

Different SQL databases have various data types to store date and time values.

MySQL

has the following date data types:

Date

Formula

- format YYYY - MM - DD

Datetime

Formula

- format: YYYY - MM - DD HH:MI:SS

Timestamp

Formula

- format: YYYY - MM - DD HH:MI:SS

Time

  • format: HH:MI:SS

Year

  • format YYYY or YY SQL Server has the following date data types:

Date

Formula

- format YYYY - MM - DD

Datetime

Formula

- format: YYYY - MM - DD HH:MI:SS

Smalldatetime

Formula

- format: YYYY - MM - DD HH:MI:SS

Time

  • format: HH:MI:SS

Timestamp

  • format: a unique number

Note:

The date data type are defined for a column upon creation of a new table in your database.

SQL Working with Dates

Look at the following table:

Orders Table

OrderId

ProductName

OrderDate

Geitost

Formula

2025 - 11 - 11

Camembert Pierrot

Formula

2025 - 11 - 09

Mozzarella di Giovanni

Formula

2025 - 11 - 11

Mascarpone Fabioli

Formula

2025 - 10 - 29
Now we want to select the records with an OrderDate of "2025 - 11 - 11" from the table above.

Previous

SQL AUTO INCREMENT Field

Next

SQL Views