MySQL - Date and Time Functions


Advertisements

MySQL provides a set of functions using which you can manipulate 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 value

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

Synonym for DAYOFMONTH()

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

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() e

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

MAKETIME()

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

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

Converts seconds to 'HH:MM:SS' format

37 SECOND()

This function returns the second (0-59)

38 STR_TO_DATE()

Converts a string to a date

39 SUBDATE()

When invoked with three arguments a synonym for DATE_SUB()

40 SUBTIME()

This function subtracts times

41 SYSDATE()

This function returns the time at which the function executes

42 TIME_FORMAT()

Formats as time

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 time

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 DATE_FORMAT()

This function formats the given date as specified.

60 TO_SECONDS()

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

mysql-useful-functions.htm
Advertisements