Back to photostream

MySQL Date and Date Functions Explained with Examples - MPS

This tutorial explains about MySQL DATE data type and walks you through some of the standard date functions. It will help you use and handle dates more efficiently with MySQL.

MySQL DATE is a temporal data type for accessing and setting dates by applications. It accepts DATE values only in YYYY-MM-DD format. And MySQL doesn’t allow to change it.

The DATE format has three subfields: Year, Month, and the date value. And, they should appear in the given order. You won’t be able to use something like MM-DD-YYYY or anything of that sort.

MySQL Date and Date Functions with Examples

Let’s now get into the internals of MySQL date and the date functions that we should know.

DATE data type in MySQL

We can use DATE for many purposes, and it is one of the most commonly used data types. MySQL provides us to use the dates in the following fixed format:

-- MySQL DATE Format

-- YEAR->MONTH->DAY

YYYY-MM-DD

We can’t alter the specified DATE template, but there are other ways to follow a different style. We’ll discuss them in a separate tutorial.

MySQL allocates three bytes to stock a DATE value. And we can use any date falling under the following range:

-- MySQL DATE Range

1000-01-01 1970-1999

Let’s re-run the previous example while we’ll specify two digits in the year. Since we are not changing the CREATE statement, so will’ skip it here. www.myprogrammingschool.com/2020/10/mysql-date-and-date-f...

17 views
0 faves
0 comments
Uploaded on October 21, 2020