Name Description: ADDDATE (Date, INTERVAL Expr Unit) Adddate (Ex
Name Description: ADDDATE (Date, INTERVAL Expr Unit) Adddate (Ex
Name Description: ADDDATE (Date, INTERVAL Expr Unit) Adddate (Ex
ADDDATE(date,INTERVAL expr unit), ADDDATE(ex
pr,days)
Add time
ADDTIME(expr1,expr2)
CONVERT_TZ(dt,from_tz,to_tz)
SELECT CONVERT_TZ('2004-01-01
12:00:00','GMT','MET');
SELECT CONVERT_TZ('2004-01-01
12:00:00','+00:00','+10:00');
CONVERT_TZ()
SELECT CURDATE();
-> '2008-06-13'
SELECT NOW();
CURRENT_TIMESTA -> '2007-12-15 23:50:26'
MP()
CURRENT_TIMESTA
MP
CURTIME()
DATE_ADD(date,INTERVAL expr unit),
DATE_SUB(date,INTERVAL expr unit)
unit Value Expected expr Format
MICROSECOND MICROSECONDS
SECOND SECONDS
MINUTE MINUTES
HOUR HOURS
DAY DAYS
WEEK WEEKS
MONTH MONTHS
QUARTER QUARTERS
YEAR YEARS
SECOND_MICROS
ECOND 'SECONDS.MICROSECONDS'
MINUTE_MICROS 'MINUTES:SECONDS.MICROSECO
ECOND NDS'
MINUTE_SECOND 'MINUTES:SECONDS'
HOUR_MICROSEC 'HOURS:MINUTES:SECONDS.MIC
OND ROSECONDS'
HOUR_SECOND 'HOURS:MINUTES:SECONDS'
HOUR_MINUTE 'HOURS:MINUTES'
'DAYS
DAY_MICROSECO HOURS:MINUTES:SECONDS.MIC
ND ROSECONDS'
DAY_SECOND 'DAYS
Name Description
HOURS:MINUTES:SECONDS'
DAY_MINUTE 'DAYS HOURS:MINUTES'
DAY_HOUR 'DAYS HOURS'
YEAR_MONTH 'YEARS-MONTHS'
DATE_FORMAT(date,format)
DATEDIFF(expr1,expr2)
DAY()
Name Description
DAYNAME(date)
SELECT DAYNAME('2007-02-03');
DAYNAME() -> 'Saturday'
DAYOFMONTH(date)
SELECT DAYOFMONTH('2007-02-03');
DAYOFMONTH() -> 3
SELECT DAYOFWEEK('2007-02-03');
DAYOFWEEK() -> 7
DAYOFYEAR(date)
SELECT DAYOFYEAR('2007-02-03');
DAYOFYEAR() -> 34
EXTRACT(unit FROM date)
-> 2009
FROM_DAYS(N)
SELECT FROM_DAYS(730669);
-> '2007-07-03'
FROM_DAYS()
FROM_UNIXTIME(unix_timestamp),
FROM_UNIXTIME(unix_timestamp,format)
Returns a representation of
the unix_timestamp argument as a value in 'YYYY-
MM-DD
HH:MM:SS' or YYYYMMDDHHMMSS.uuuuuu format
SELECT FROM_UNIXTIME(1447430881);
-> '2015-11-13 10:08:01'
SELECT FROM_UNIXTIME(UNIX_TIMESTAMP(),
-> '%Y %D %M %h:%i:%s %x');
FROM_UNIXTIME() -> '2015 13th November 10:08:01 2015'
Name Description
GET_FORMAT({DATE|TIME|DATETIME},
{'EUR'|'USA'|'JIS'|'ISO'|'INTERNAL'})
RNAL')
Extract the hour
HOUR(time)
SELECT HOUR('10:05:03');
-> 10
SELECT HOUR('272:59:59');
-> 272
LAST_DAY(date)
SELECT LAST_DAY('2003-02-05');
-> '2003-02-28'
SELECT LAST_DAY('2004-02-05');
-> '2004-02-29'
SELECT LAST_DAY('2003-03-32');
LAST_DAY -> NULL
LOCALTIME()
LOCALTIME Synonym for NOW()
LOCALTIMESTAMP
LOCALTIMESTAMP() Synonym for NOW()
MAKEDATE(year,dayofyear)
SELECT MAKEDATE(2011,365),
MAKEDATE(2014,365);
-> '2011-12-31', '2014-12-31'
MAKETIME(hour,minute,second)
SELECT MAKETIME(12,15,30);
MAKETIME() -> '12:15:30'
SELECT MICROSECOND('12:00:00.123456');
-> 123456
MINUTE(time)
Returns the minute for time, in the range 0 to 59.
MONTH(date)
Returns the month for date, in the range 1 to 12 for
January to December, or 0 for dates such as '0000-
00-00' or '2008-00-00' that have a zero month part.
SELECT MONTH('2008-02-03');
-> 2
MONTH()
Name Description
MONTHNAME(date)
SELECT MONTHNAME('2008-02-03');
-> 'February'
MONTHNAME()
PERIOD_ADD(P,N)
Adds N months to period P (in the
format YYMM or YYYYMM). Returns a value in the
format YYYYMM
Note that the period argument P is not a date value
SELECT PERIOD_ADD(200801,2);
-> 200803
PERIOD_ADD()
PERIOD_DIFF(P1,P2)
SELECT PERIOD_DIFF(200802,200703);
PERIOD_DIFF() -> 11
QUARTER(date)
SELECT QUARTER('2008-04-01');
Name Description
-> 2
SEC_TO_TIME(seconds)
Returns the seconds argument, converted to hours,
minutes, and seconds, as a TIME value
SELECT SEC_TO_TIME(2378);
-> '00:39:38'
SEC_TO_TIME()
SECOND(time)
SELECT SECOND('10:05:03');
-> 3
SECOND()
STR_TO_DATE(str,format)
SELECT STR_TO_DATE('01,5,2013','%d,%m,%Y');
-> '2013-05-01'
SELECT STR_TO_DATE('9','%s');
STR_TO_DATE() -> '00:00:09'
arguments
SUBDATE(date,INTERVAL expr unit),
SUBDATE(expr,days)
-> '2007-12-02'
SELECT SUBDATE('2008-01-02', INTERVAL 31 DAY);
-> '2007-12-02'
Subtract times
SUBTIME(expr1,expr2)
SUBTIME() returns expr1 − expr2 expressed as a
value in the same format as expr1.
SELECT SUBTIME('01:00:00.999999',
'02:00:00.999998');
SUBTIME() -> '-00:59:59.999999'
TIME(expr)
TIME()
Format as time
TIME_FORMAT(time,format)
TIME_FORMAT()
TIME_TO_SEC(time)
SELECT TIME_TO_SEC('22:23:00');
Name Description
-> 80580
SELECT TIME_TO_SEC('00:39:38');
-> 2378
Subtract time
TIMEDIFF(expr1,expr2)
TIMEDIFF() returns expr1 − expr2 expressed as a
time value. expr1 andexpr2 are time or date-and-
time expressions, but both must be of the same
type.
TIMEDIFF()
TIMESTAMP(expr),
TIMESTAMP(expr1,expr2)
SELECT TIMESTAMP('2003-12-31');
-> '2003-12-31 00:00:00'
SELECT TIMESTAMP('2003-12-31
12:00:00','12:00:00');
TIMESTAMP() -> '2004-01-01 00:00:00'
SELECT TIMESTAMPADD(MINUTE,1,'2003-01-02');
-> '2003-01-02 00:01:00'
SELECT TIMESTAMPADD(WEEK,1,'2003-01-02');
-> '2003-01-09'
TIMESTAMPDIFF(unit, datetime_expr1,
datetime_expr2)
Returns datetime_expr2 − datetime_expr1,
where datetime_expr1 anddatetime_expr2 are
date or datetime expressions. One expression may
be a date and the other a datetime; a date value is
treated as a datetime having the time
part '00:00:00' where necessary
SELECT TIMESTAMPDIFF(MONTH,'2003-02-
01','2003-05-01');
-> 3
SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-
01-01');
-> -1
SELECT TIMESTAMPDIFF(MINUTE,'2003-02-
01','2003-05-01 12:05:55');
Name Description
-> 128885
TO_DAYS(date)
SELECT TO_DAYS('2007-10-07');
-> 733321
TO_SECONDS(expr)
SELECT TO_SECONDS('2009-11-29');
-> 63426672000
TO_SECONDS()
UNIX_TIMESTAMP(), UNIX_TIMESTAMP(date)
If called with no argument, returns a Unix timestamp
(seconds since '1970-01-01 00:00:00' UTC) as an
unsigned integer.
orYYYYMMDDHHMMSS format
SELECT UNIX_TIMESTAMP();
-> 1447431666
SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19');
-> 1447431619
+---------------------------------------+
| UNIX_TIMESTAMP('1970-01-01 05:30:01') |
+---------------------------------------+
| 1|
+---------------------------------------+
SELECT UTC_DATE()
UTC_DATE()
-> '2003-08-14'
Return the current UTC time
UTC_TIME, UTC_TIME()
SELECT UTC_TIME();
UTC_TIME()
-> '18:07:53'
UTC_TIMESTAMP() Return the current UTC date and time
in 'YYYY-MM-DD
HH:MM:SS'or YYYYMMDDHHMMSS.uuuuuu format
SELECT UTC_TIMESTAMP();
-> '2003-08-14 18:08:04'
WEEK(date)
WEEK()
WEEKDAY(date)
WEEKOFYEAR(date)
Returns the calendar week of the date as a number
in the range from 1 to 53.
Name Description
SELECT WEEKOFYEAR('2008-02-20');
-> 8
YEAR(date)
Returns the year for date, in the
range 1000 to 9999, or 0 for the “zero” date
SELECT YEAR('1987-01-01');
-> 1987
YEAR()
YEARWEEK(date)