Skip to content

Date and time functions

Date arithmetic, formatting, parsing, extraction and clock values.

Date arithmetic, formatting, parsing, extraction and clock values.

adddate

addtime

convert_tz

SignaturePurposeSource definition
mysql.convert_tz(text, text, text) → timestamp without time zoneConvert a temporal value between time zones.SQL
mysql.convert_tz(timestamp without time zone, text, text) → timestamp without time zoneConvert a temporal value between time zones.SQL

curdate

SignaturePurposeSource definition
mysql.curdate() → dateReturn the current date.SQL

curtime

SignaturePurposeSource definition
mysql.curtime() → time without time zoneReturn the current time of day.SQL
mysql.curtime(prec integer) → time without time zoneReturn the current time of day.SQL

date

SignaturePurposeSource definition
mysql.date(numeric) → dateExtract or parse a date.SQL
pg_catalog.date(text) → dateExtract or parse a date.SQL

date_add

SignaturePurposeSource definition
mysql.date_add(date, interval) → dateAdd a day count or interval to a date.SQL
mysql.date_add(numeric, interval) → timestamp without time zoneAdd a day count or interval to a date.SQL
mysql.date_add(text, interval) → timestamp without time zoneAdd a day count or interval to a date.SQL
mysql.date_add(timestamp without time zone, interval) → timestamp without time zoneAdd a day count or interval to a date.SQL

date_format

SignaturePurposeSource definition
mysql.date_format(text, text) → textFormat a date with MySQL percent directives.SQL
mysql.date_format(timestamp with time zone, text) → textFormat a date with MySQL percent directives.SQL

date_sub

SignaturePurposeSource definition
mysql.date_sub(date, interval) → dateSubtract a day count or interval from a date.SQL
mysql.date_sub(numeric, interval) → timestamp without time zoneSubtract a day count or interval from a date.SQL
mysql.date_sub(text, interval) → timestamp without time zoneSubtract a day count or interval from a date.SQL
mysql.date_sub(timestamp without time zone, interval) → timestamp without time zoneSubtract a day count or interval from a date.SQL

datediff

SignaturePurposeSource definition
mysql.datediff(date, date) → integerReturn the difference between two dates in days.SQL
mysql.datediff(numeric, numeric) → integerReturn the difference between two dates in days.SQL
mysql.datediff(numeric, text) → integerReturn the difference between two dates in days.SQL
mysql.datediff(text, numeric) → integerReturn the difference between two dates in days.SQL
mysql.datediff(text, text) → integerReturn the difference between two dates in days.SQL
mysql.datediff(text, timestamp without time zone) → integerReturn the difference between two dates in days.SQL
mysql.datediff(timestamp without time zone, text) → integerReturn the difference between two dates in days.SQL
mysql.datediff(timestamp without time zone, timestamp without time zone) → integerReturn the difference between two dates in days.SQL

day

SignaturePurposeSource definition
mysql.day(numeric) → integerReturn the day of the month.SQL
mysql.day(text) → integerReturn the day of the month.SQL
mysql.day(timestamp without time zone) → integerReturn the day of the month.SQL

dayname

SignaturePurposeSource definition
mysql.dayname(numeric) → textReturn the weekday name.SQL
mysql.dayname(text) → textReturn the weekday name.SQL
mysql.dayname(timestamp without time zone) → textReturn the weekday name.SQL

dayofmonth

SignaturePurposeSource definition
mysql.dayofmonth(numeric) → integerReturn the day of the month.SQL
mysql.dayofmonth(text) → integerReturn the day of the month.SQL
mysql.dayofmonth(timestamp without time zone) → integerReturn the day of the month.SQL

dayofweek

SignaturePurposeSource definition
mysql.dayofweek(numeric) → integerNumber weekdays starting with Sunday as 1.SQL
mysql.dayofweek(text) → integerNumber weekdays starting with Sunday as 1.SQL
mysql.dayofweek(timestamp without time zone) → integerNumber weekdays starting with Sunday as 1.SQL

dayofyear

SignaturePurposeSource definition
mysql.dayofyear(numeric) → integerReturn the ordinal day of the year.SQL
mysql.dayofyear(text) → integerReturn the ordinal day of the year.SQL
mysql.dayofyear(timestamp without time zone) → integerReturn the ordinal day of the year.SQL

extract

SignaturePurposeSource definition
mysql."extract"(text, text) → numericExtract the requested date or time field.SQL
mysql."extract"(text, time without time zone) → numericExtract the requested date or time field.SQL · C
mysql."extract"(text, timestamp without time zone) → numericExtract the requested date or time field.SQL · C

from_days

SignaturePurposeSource definition
mysql.from_days(integer) → dateConvert a MySQL day number to a date.SQL

from_unixtime

SignaturePurposeSource definition
mysql.from_unixtime(double precision) → timestamp without time zoneConvert Unix time to a date/time value or formatted string.SQL
mysql.from_unixtime(double precision, text) → textConvert Unix time to a date/time value or formatted string.SQL

hour

last_day

SignaturePurposeSource definition
mysql.last_day(date) → dateFind the last date of the month.SQL
mysql.last_day(numeric) → dateFind the last date of the month.SQL
mysql.last_day(text) → dateFind the last date of the month.SQL
mysql.last_day(timestamp with time zone) → dateFind the last date of the month.SQL
mysql.last_day(timestamp without time zone) → dateFind the last date of the month.SQL

makedate

SignaturePurposeSource definition
mysql.makedate(integer, integer) → dateBuild a date from a year and day of year.SQL

maketime

SignaturePurposeSource definition
mysql.maketime(integer, integer, numeric) → time without time zoneBuild a time from hours, minutes and seconds.SQL

microsecond

minute

month

SignaturePurposeSource definition
mysql.month(numeric) → integerReturn the month number.SQL
mysql.month(text) → integerReturn the month number.SQL
mysql.month(timestamp without time zone) → integerReturn the month number.SQL

monthname

SignaturePurposeSource definition
mysql.monthname(numeric) → textReturn the month name.SQL
mysql.monthname(text) → textReturn the month name.SQL
mysql.monthname(timestamp without time zone) → textReturn the month name.SQL

now

SignaturePurposeSource definition
mysql.now() → timestamp without time zoneReturn the transaction’s current timestamp.SQL
mysql.now(prec integer) → timestamp without time zoneReturn the transaction’s current timestamp.SQL

period_add

SignaturePurposeSource definition
mysql.period_add(integer, integer) → textAdd months to a year-month period.SQL

period_diff

SignaturePurposeSource definition
mysql.period_diff(integer, integer) → integerFind the difference between year-month periods in months.SQL

quarter

SignaturePurposeSource definition
mysql.quarter(date) → integerReturn the quarter of the year.SQL
mysql.quarter(numeric) → integerReturn the quarter of the year.SQL
mysql.quarter(text) → integerReturn the quarter of the year.SQL
mysql.quarter(timestamp without time zone) → integerReturn the quarter of the year.SQL

sec_to_time

SignaturePurposeSource definition
mysql.sec_to_time(bigint) → time without time zoneConvert seconds to a time value.SQL

second

str_to_date

SignaturePurposeSource definition
mysql.str_to_date(text, text) → timestamp without time zoneParse a date or time with a MySQL format string.SQL

subdate

SignaturePurposeSource definition
mysql.subdate(date, integer) → dateSubtract a day count or interval from a date.SQL
mysql.subdate(date, interval) → timestamp without time zoneSubtract a day count or interval from a date.SQL
mysql.subdate(numeric, integer) → timestamp without time zoneSubtract a day count or interval from a date.SQL
mysql.subdate(numeric, interval) → timestamp without time zoneSubtract a day count or interval from a date.SQL
mysql.subdate(text, integer) → timestamp without time zoneSubtract a day count or interval from a date.SQL
mysql.subdate(text, interval) → timestamp without time zoneSubtract a day count or interval from a date.SQL
mysql.subdate(timestamp without time zone, integer) → timestamp without time zoneSubtract a day count or interval from a date.SQL
mysql.subdate(timestamp without time zone, interval) → timestamp without time zoneSubtract a day count or interval from a date.SQL

subtime

sysdate

SignaturePurposeSource definition
mysql.sysdate() → timestamp without time zoneRead the wall clock at execution time.SQL
mysql.sysdate(prec integer) → timestamp without time zoneRead the wall clock at execution time.SQL

time_format

SignaturePurposeSource definition
mysql.time_format(time without time zone, text) → textFormat a time value.SQL

time_to_sec

SignaturePurposeSource definition
mysql.time_to_sec(text) → bigintConvert a time value to seconds.SQL
mysql.time_to_sec(time without time zone) → bigintConvert a time value to seconds.SQL
mysql.time_to_sec(timestamp without time zone) → bigintConvert a time value to seconds.SQL

timediff

SignaturePurposeSource definition
mysql.timediff(text, text) → textReturn the difference between two time values.SQL · C
mysql.timediff(time without time zone, time without time zone) → textReturn the difference between two time values.SQL
mysql.timediff(timestamp without time zone, timestamp without time zone) → textReturn the difference between two time values.SQL · C

timestamp

SignaturePurposeSource definition
mysql."timestamp"(text, text) → timestamp without time zoneBuild a timestamp from the supplied date/time arguments.SQL

timestampadd

SignaturePurposeSource definition
mysql.timestampadd(text, integer, timestamp without time zone) → timestamp without time zoneAdd a quantity in the specified temporal unit.SQL

timestampdiff

SignaturePurposeSource definition
mysql.timestampdiff(unit text, ts1 text, ts2 text) → bigintMeasure a timestamp difference in the specified unit.SQL
mysql.timestampdiff(unit text, ts1 timestamp without time zone, ts2 timestamp without time zone) → bigintMeasure a timestamp difference in the specified unit.SQL · C

to_days

SignaturePurposeSource definition
mysql.to_days(date) → integerConvert a date to a MySQL day number.SQL
mysql.to_days(text) → integerConvert a date to a MySQL day number.SQL
mysql.to_days(timestamp without time zone) → integerConvert a date to a MySQL day number.SQL

unix_timestamp

SignaturePurposeSource definition
mysql.unix_timestamp() → bigintReturn seconds since the Unix epoch.SQL
mysql.unix_timestamp(numeric) → numericReturn seconds since the Unix epoch.SQL
mysql.unix_timestamp(text) → numericReturn seconds since the Unix epoch.SQL
mysql.unix_timestamp(timestamp without time zone) → numericReturn seconds since the Unix epoch.SQL

utc_date

SignaturePurposeSource definition
mysql.utc_date() → dateReturn the current date in UTC.SQL

utc_time

SignaturePurposeSource definition
mysql.utc_time() → time without time zoneReturn the current time of day in UTC.SQL
mysql.utc_time(prec integer) → time without time zoneReturn the current time of day in UTC.SQL

utc_timestamp

SignaturePurposeSource definition
mysql.utc_timestamp() → timestamp without time zoneReturn the current UTC timestamp.SQL
mysql.utc_timestamp(prec integer) → timestamp without time zoneReturn the current UTC timestamp.SQL

week

SignaturePurposeSource definition
mysql.week(numeric) → integerReturn the week number under the selected week mode.SQL
mysql.week(numeric, integer) → integerReturn the week number under the selected week mode.SQL
mysql.week(text) → integerReturn the week number under the selected week mode.SQL
mysql.week(text, integer) → integerReturn the week number under the selected week mode.SQL
mysql.week(timestamp without time zone) → integerReturn the week number under the selected week mode.SQL
mysql.week(timestamp without time zone, integer) → integerReturn the week number under the selected week mode.SQL

weekday

SignaturePurposeSource definition
mysql.weekday(numeric) → integerNumber weekdays starting with Monday as 0.SQL
mysql.weekday(text) → integerNumber weekdays starting with Monday as 0.SQL
mysql.weekday(timestamp without time zone) → integerNumber weekdays starting with Monday as 0.SQL

weekofyear

SignaturePurposeSource definition
mysql.weekofyear(numeric) → integerReturn the week of the year.SQL
mysql.weekofyear(text) → integerReturn the week of the year.SQL
mysql.weekofyear(timestamp without time zone) → integerReturn the week of the year.SQL

year

SignaturePurposeSource definition
mysql.year(date) → integerExtract the year.SQL
mysql.year(numeric) → integerExtract the year.SQL
mysql.year(text) → integerExtract the year.SQL
mysql.year(timestamp without time zone) → integerExtract the year.SQL

yearweek

SignaturePurposeSource definition
mysql.yearweek(numeric) → integerReturn the week and its associated year.SQL
mysql.yearweek(qdate numeric, mode integer) → integerReturn the week and its associated year.SQL
mysql.yearweek(qdate text, mode integer) → integerReturn the week and its associated year.SQL
mysql.yearweek(qdate timestamp without time zone, mode integer) → integerReturn the week and its associated year.SQL
mysql.yearweek(text) → integerReturn the week and its associated year.SQL
mysql.yearweek(timestamp without time zone) → integerReturn the week and its associated year.SQL