MySQL – Date and Time Functions
”;
In MySQL, we have a set of functions using which we can manipulate the date and time values. Following are the MySQL date time functions −
Sr.No. | Name & Description |
---|---|
1 | ADDDATE()
This function adds two given dates |
2 | ADDTIME()
This function adds given time values |
3 | CONVERT_TZ()
This function converts from one timezone to another |
4 | CURDATE()
This function returns the current date |
5 | CURRENT_DATE(), CURRENT_DATE
Synonyms for CURDATE() |
6 | CURRENT_TIME(), CURRENT_TIME
Synonyms for CURTIME() |
7 | CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP
Synonyms for NOW() |
8 | CURTIME()
This function returns the current time |
9 | DATE_ADD()
Adds two dates |
10 | DATE_FORMAT()
This function formats the given date as specified |
11 | DATE_SUB()
This function subtracts two dates |
12 | DATE()
This function extracts the date part of a date or datetime expression |
13 | DATEDIFF()
This function subtracts two dates |
14 | DAY()
This function retrieves the day of the month from the given date |
15 | DAYNAME()
This function returns the name of the weekday |
16 | DAYOFMONTH()
This function returns the day of the month (1-31) |
17 | DAYOFWEEK()
This function returns the weekday index of the argument |
18 | DAYOFYEAR()
This function returns the day of the year (1-366) |
19 | EXTRACT
This function extracts part of a date |
20 | FROM_DAYS()
This function converts a day number to a date |
21 | FROM_UNIXTIME()
This function formats date as a UNIX timestamp |
22 | HOUR()
This function Extracts the hour |
23 | LAST_DAY
This function returns the last day of the month for the argument |
24 | LOCALTIME(), LOCALTIME
Synonym for NOW() |
25 | LOCALTIMESTAMP, LOCALTIMESTAMP()
Synonym for NOW() |
26 | MAKEDATE()
This function creates a date from the year and day of year |
27 | MAKETIME()
This function creates a time value from the given hours, minutes, and seconds. |
28 | MICROSECOND()
This function returns the microseconds from argument |
29 | MINUTE()
This function returns the minute from the argument |
30 | MONTH()
This function returns the month from the date passed |
31 | MONTHNAME()
This function returns the name of the month |
32 | NOW()
This function returns the current date and time |
33 | PERIOD_ADD()
This function adds a period to a year-month |
34 | PERIOD_DIFF()
This function returns the number of months between periods |
35 | QUARTER()
This function returns the quarter from a date argument |
36 | SEC_TO_TIME()
This function converts seconds to ”HH:MM:SS” format |
37 | SECOND()
This function returns the second (0-59) |
38 | STR_TO_DATE()
This function converts a string to a date |
39 | SUBDATE()
This function subtracts the specified interval to a date value |
40 | SUBTIME()
This function subtracts the specified time interval to a date time or, time value |
41 | SYSDATE()
This function returns the time at which the function executes |
42 | TIME_FORMAT()
This function formats the given date in the specified format |
43 | TIME_TO_SEC()
This function returns the argument converted to seconds |
44 | TIME()
This function extracts the time portion of the expression passed |
45 | TIMEDIFF()
This function subtracts two time values |
46 | TIMESTAMP()
With a single argument, this function returns the date or datetime expression. With two arguments, the sum of the arguments |
47 | TIMESTAMPADD()
This function adds an interval to a datetime expression |
48 | TIMESTAMPDIFF()
This function subtracts an interval from a datetime expression |
49 | TO_DAYS()
This function returns the date argument converted to days |
50 | UNIX_TIMESTAMP()
This function returns a UNIX timestamp |
51 | UTC_DATE()
This function returns the current UTC date |
52 | UTC_TIME()
This function returns the current UTC time |
53 | UTC_TIMESTAMP()
This function returns the current UTC date and time |
54 | WEEK()
This function returns the week number |
55 | WEEKDAY()
This function returns the weekday index |
56 | WEEKOFYEAR()
This function returns the calendar week of the date (1-53) |
57 | YEAR()
This function returns the year |
58 | YEARWEEK()
This function returns the year and week |
59 | TO_SECONDS()
This function converts the date or date-time values into seconds and returns the result. |
”;