MySQL QUARTER Function

Example

Return the quarter of the year for the date:

SELECT QUARTER("2017-06-15");

Definition and Usage

The QUARTER() function returns the quarter of the year for a given date value (a number from 1 to 4).

  • January-March returns 1
  • April-June returns 2
  • July-Sep returns 3
  • Oct-Dec returns 4

Syntax

QUARTER(date)

Continue reading MySQL QUARTER Function

MySQL PERIOD_DIFF Function

Example

Return the difference between two periods:

SELECT PERIOD_DIFF(201710, 201703);

Definition and Usage

The PERIOD_DIFF() function returns the difference between two periods. The result will be in months.

Note: period1 and period2 should be in the same format.

Syntax

PERIOD_DIFF(period1, period2)

Continue reading MySQL PERIOD_DIFF Function

MySQL PERIOD_ADD Function

Example

Add a specified number of months to a period:

SELECT PERIOD_ADD(201703, 5);

Definition and Usage

The PERIOD_ADD() function adds a specified number of months to a period.

The PERIOD_ADD() function will return the result formatted as YYYYMM.

Syntax

PERIOD_ADD(period, number)

Continue reading MySQL PERIOD_ADD Function

MySQL NOW Function

Example

Return current date and time:

SELECT NOW();

Definition and Usage

The NOW() function returns the current date and time.

Note: The date and time is returned as “YYYY-MM-DD HH-MM-SS” (string) or as YYYYMMDDHHMMSS.uuuuuu (numeric).

Syntax

NOW()

Continue reading MySQL NOW Function

MySQL MONTHNAME Function

Example

Return the name of the month for a date:

SELECT MONTHNAME("2017-06-15");

Definition and Usage

The MONTHNAME() function returns the name of the month for a given date.

Syntax

MONTHNAME(date)

Continue reading MySQL MONTHNAME Function

MySQL MONTH Function

Example

Return the month part of a date:

SELECT MONTH("2017-06-15");

Definition and Usage

The MONTH() function returns the month part for a given date (a number from 1 to 12).

Syntax

MONTH(date)

Continue reading MySQL MONTH Function

MySQL MINUTE Function

Example

Return the minute part of a datetime value:

SELECT MINUTE("2017-06-20 09:34:00");

Definition and Usage

The MINUTE() function returns the minute part of a time/datetime (from 0 to 59).

Syntax

MINUTE(datetime)

Continue reading MySQL MINUTE Function

MySQL MICROSECOND Function

Example

Return the microsecond part of a datetime:

SELECT MICROSECOND("2017-06-20 09:34:00.000023");

Definition and Usage

The MICROSECOND() function returns the microsecond part of a time/datetime (from 0 to 999999). Continue reading MySQL MICROSECOND Function

MySQL MAKETIME Function

Example

Create and return a time value based on an hour, minute, and second value:

SELECT MAKETIME(11, 35, 4);

Definition and Usage

The MAKETIME() function creates and returns a time based on an hour, minute, and second value.

Syntax

MAKETIME(hour, minute, second)

Continue reading MySQL MAKETIME Function

MySQL MAKEDATE Function

Example

Create and return a date based on  a year and a number of days value:

SELECT MAKEDATE(2017, 3);

Definition and Usage

The MAKEDATE() function creates and returns a date based on a year and a number of days value. Continue reading MySQL MAKEDATE Function