MySQL has a PERIOD_DIFF()
function that enables you to find the difference between two periods. The periods are provided as two separate arguments, and they should in the format YYMM or YYYYMM.
Category: DBMS
Database Management Systems
PERIOD_ADD() Examples – MySQL
MySQL has a PERIOD_ADD()
function that allows you to add a number of months to a given period. It returns a value in the format YYYYMM.
This article provides examples to demonstrate how it works.
MONTHNAME() Examples – MySQL
In MySQL, the MONTHNAME()
function returns the month name from a date.
For example, if you provide a date of 2021-12-07, the MONTHNAME()
function will return December.
MONTH() Examples – MySQL
You can use the MONTH()
function in MySQL to return the month from a date.
In this context, the month is a value between 1 and 12 (or 0 for dates with a zero month part).
For example, if you provide a date of 2018-10-07, the MONTH()
function will return 10.
MAKETIME() Examples – MySQL
When using MySQL, you can use the MAKETIME()
function to return a time from the various time parts.
In other words, you provide three arguments; the hour, the minutes, and the seconds. The MAKETIME()
function will then return the time value based on those two arguments.
MAKEDATE() Examples – MySQL
When using MySQL, you can use the MAKEDATE()
function to return a date from the year and day-of-year parts.
In other words, you provide two arguments; one being the year, and the other being the day-of-year. The MAKEDATE()
function will then return the date value based on those two arguments.
LOCALTIME Examples – MySQL
LOCALTIMESTAMP Examples – MySQL
LAST_DAY() Examples – MySQL
When using MySQL, you can use the LAST_DAY()
function to return the last day of a given month.
You can provide the current date, or you can provide another specified date (for example, a date from a column in a database), and LAST_DAY()
will return the last day of the month for that date.
MICROSECOND() Example – MySQL
The MySQL MICROSECOND()
function is used to return the microsecond component from a time value.
The return value for this function is in the range 0 to 999999. Below are examples to demonstrate.