Example
Return a date based on a string and a format:
SELECT STR_TO_DATE("August 10 2017", "%M %d %Y");
Definition and Usage
The STR_TO_DATE() function returns a date based on a string and a format.
Syntax
STR_TO_DATE(string, format)
Return a date based on a string and a format:
SELECT STR_TO_DATE("August 10 2017", "%M %d %Y");
The STR_TO_DATE() function returns a date based on a string and a format.
STR_TO_DATE(string, format)
Return a time value based on a specified seconds value:
SELECT SEC_TO_TIME(1);
The SEC_TO_TIME() function returns a time value (in format HH:MM:SS) based on the specified seconds.
SEC_TO_TIME(seconds)
Return the seconds part of a datetime value:
SELECT SECOND("2017-06-20 09:34:00.000023");
The SECOND() function returns the seconds part of a time/datetime (from 0 to 59).
SECOND(datetime)
Return the quarter of the year for the date:
SELECT QUARTER("2017-06-15");
The QUARTER() function returns the quarter of the year for a given date value (a number from 1 to 4).
QUARTER(date)
Return the difference between two periods:
SELECT PERIOD_DIFF(201710, 201703);
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.
PERIOD_DIFF(period1, period2)
Add a specified number of months to a period:
SELECT PERIOD_ADD(201703, 5);
The PERIOD_ADD() function adds a specified number of months to a period.
The PERIOD_ADD() function will return the result formatted as YYYYMM.
PERIOD_ADD(period, number)
Return current date and time:
SELECT NOW();
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).
NOW()
Return the name of the month for a date:
SELECT MONTHNAME("2017-06-15");
The MONTHNAME() function returns the name of the month for a given date.
MONTHNAME(date)
Return the month part of a date:
SELECT MONTH("2017-06-15");
The MONTH() function returns the month part for a given date (a number from 1 to 12).
MONTH(date)
Return the minute part of a datetime value:
SELECT MINUTE("2017-06-20 09:34:00");
The MINUTE() function returns the minute part of a time/datetime (from 0 to 59).
MINUTE(datetime)