Member-only story
MySQL EXTRACT() method for specific DATE and TIME values
Date and time values are some of the most important datatypes in an RDBMS. From tracking order dates to payroll hours, DATE
and DATETIME
datatypes are used in all types of applications. At times as a Developer, you may need only certain portions of a DATE
or DATETIME
value. In MySQL, the EXTRACT()
function can provide you with a specific component of a DATE
or DATETIME
value depending on which INTERVAL
is given as a parameter. Continue reading to see example EXTRACT()
queries for understanding…
OS, Software, and DB used:
- OpenSuse Leap 15.1
- MySQL 8.0.20
Self-Promotion:
If you enjoy the content written here, by all means, share this blog and your favorite post(s) with others who may benefit from or like it as well. Since coffee is my favorite drink, you can even buy me one if you would like!
I’ll use the SET
command and assign a session variable the CURRENT_TIMESTAMP
value to that of the date this post’ examples were written:
MySQL localhost:33060+ ssl learning SQL > SET @a_date = CURRENT_TIMESTAMP;MySQL localhost:33060+ ssl learning SQL > SELECT @a_date;
+ — — — — — — — — — — -+
| @a_date |
+ — — — — — — — — — — -+
| 2020–05–30 09:09:23 |
+ — — — — — — — — —…