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
1ADDDATE()

This function adds two given dates

2ADDTIME()

This function adds given time values

3CONVERT_TZ()

This function converts from one timezone to another

4CURDATE()

This function returns the current date

5CURRENT_DATE(), CURRENT_DATE

Synonyms for CURDATE()

6CURRENT_TIME(), CURRENT_TIME

Synonyms for CURTIME()

7CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP

Synonyms for NOW()

8CURTIME()

This function returns the current time

9DATE_ADD()

Adds two dates

10DATE_FORMAT()

This function formats the given date as specified

11DATE_SUB()

This function subtracts two dates

12DATE()

This function extracts the date part of a date or datetime expression

13DATEDIFF()

This function subtracts two dates

14DAY()

This function retrieves the day of the month from the given date

15DAYNAME()

This function returns the name of the weekday

16DAYOFMONTH()

This function returns the day of the month (1-31)

17DAYOFWEEK()

This function returns the weekday index of the argument

18DAYOFYEAR()

This function returns the day of the year (1-366)

19EXTRACT

This function extracts part of a date

20FROM_DAYS()

This function converts a day number to a date

21FROM_UNIXTIME()

This function formats date as a UNIX timestamp

22HOUR()

This function Extracts the hour

23LAST_DAY

This function returns the last day of the month for the argument

24LOCALTIME(), LOCALTIME

Synonym for NOW()

25LOCALTIMESTAMP, LOCALTIMESTAMP()

Synonym for NOW()

26MAKEDATE()

This function creates a date from the year and day of year

27MAKETIME()

This function creates a time value from the given hours, minutes, and seconds.

28MICROSECOND()

This function returns the microseconds from argument

29MINUTE()

This function returns the minute from the argument

30MONTH()

This function returns the month from the date passed

31MONTHNAME()

This function returns the name of the month

32NOW()

This function returns the current date and time

33PERIOD_ADD()

This function adds a period to a year-month

34PERIOD_DIFF()

This function returns the number of months between periods

35QUARTER()

This function returns the quarter from a date argument

36SEC_TO_TIME()

This function converts seconds to 'HH:MM:SS' format

37SECOND()

This function returns the second (0-59)

38STR_TO_DATE()

This function converts a string to a date

39SUBDATE()

This function subtracts the specified interval to a date value

40SUBTIME()

This function subtracts the specified time interval to a date time or, time value

41SYSDATE()

This function returns the time at which the function executes

42TIME_FORMAT()

This function formats the given date in the specified format

43TIME_TO_SEC()

This function returns the argument converted to seconds

44TIME()

This function extracts the time portion of the expression passed

45TIMEDIFF()

This function subtracts two time values

46TIMESTAMP()

With a single argument, this function returns the date or datetime expression. With two arguments, the sum of the arguments

47TIMESTAMPADD()

This function adds an interval to a datetime expression

48TIMESTAMPDIFF()

This function subtracts an interval from a datetime expression

49TO_DAYS()

This function returns the date argument converted to days

50UNIX_TIMESTAMP()

This function returns a UNIX timestamp

51UTC_DATE()

This function returns the current UTC date

52UTC_TIME()

This function returns the current UTC time

53UTC_TIMESTAMP()

This function returns the current UTC date and time

54WEEK()

This function returns the week number

55WEEKDAY()

This function returns the weekday index

56WEEKOFYEAR()

This function returns the calendar week of the date (1-53)

57YEAR()

This function returns the year

58YEARWEEK()

This function returns the year and week

59TO_SECONDS()

This function converts the date or date-time values into seconds and returns the result.