🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to MySQL Notes
Topic #61

MySQL Dates


MySQL 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.


MySQL Date Data Types

MySQL has the following data types for storing a date or a date/time value in the database:

  • DATE - format YYYY-MM-DD
  • DATETIME - format: YYYY-MM-DD HH:MI:SS
  • TIMESTAMP - format: YYYY-MM-DD HH:MI:SS
  • TIME - format: HH:MI:SS
  • YEAR - format YYYY or YY

Note: The date datatype are defined for a column upon creation of a new table in your database.


MySQL Working with Dates

Look at the following table:

Orders Table

OrderId ProductName OrderDate
1 Geitost 2025-11-11
2 Camembert Pierrot 2025-11-09
3 Mozzarella di Giovanni 2025-11-11
4 Mascarpone Fabioli 2025-10-29

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

We use the following SELECT statement:

SELECT * FROM Orders WHERE OrderDate='2025-11-11'

The result-set will look like this:

OrderId ProductName OrderDate
1 Geitost 2025-11-11
3 Mozzarella di Giovanni 2025-11-11

Note: Two dates can easily be compared if there is no time component involved!

Now, assume that the "Orders" table looks like this (notice the added time-component in the "OrderDate" column):

OrderId ProductName OrderDate
1 Geitost 2025-11-11 13:23:44
2 Camembert Pierrot 2025-11-09 15:45:21
3 Mozzarella di Giovanni 2025-11-11 11:12:01
4 Mascarpone Fabioli 2025-10-29 14:56:59

If we use the same SELECT statement as above:

SELECT * FROM Orders WHERE OrderDate='2025-11-11'

we will get no result! This is because the query is looking only for dates with no time portion.

Tip: To keep your queries simple and easy to maintain, do not use time-components in your dates, unless you have to!

Want to go beyond the notes?

Join CodingNow 2.0's MySQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

MySQL Dates – FAQs

Quick answers about learning MySQL Dates in MySQL.

This free note from CodingNow 2.0 explains MySQL Dates in MySQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every MySQL topic on CodingNow 2.0, including MySQL Dates, is 100% free with no signup required.
With focused practice, most students grasp MySQL Dates in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now