Home >> FAQs/Tutorials >> MySQL Tutorials

MySQL Tutorial - Date and Time Functions

By: FYIcenter.com

(Continued from previous topic...)

What Are Date and Time Functions?

MySQL offers a number of functions for date and time values:

  • ADDDATE(date, INTERVAL expr unit) - Adding days to a date. Same as DATE_ADD().
  • ADDTIME(time1, time2) - Adding two time values together.
  • CURDATE() - Returning the current date. Same as CURRENT_DATE().
  • CURTIME() - Returning the current time. Same as CURRENT_TIME().
  • DATE(expression) - Returning the date from the expression.
  • DATEDIFF(date1, date2) - Returning dates difference in days.
  • DATE_ADD(date, INTERVAL expr unit) - Adding days to a date.
  • DATE_SUB(date, INTERVAL expr unit) - Subtracting days from a date.
  • DATE_FORMAT(date, format) - Returning a character string representing a date.
  • DAY(date) - Returning an integer representing the day of the month. Same as DAYOFMONTH()
  • DAYNAME(date) - Returning the name of week day.
  • DAYOFMONTH(date) - Returning an integer representing the day of the month.
  • DAYOFWEEK(date) - Returning an integer representing the day of the week.
  • DAYOFYEAR(date) - Returning an integer representing the day of the year.
  • EXTRACT(unit FROM date) - Returning a unit value of a date and time.
  • HOUR(time) - Returning the hour value of a time
  • LAST_DAY(date) - Returning a date representing the last day of the month based on the given date.
  • LOCALTIME() - Returning the current date and time. Same as NOW().
  • MAKETIME(hour,minute,second) - Returning a date based on the given time unit values.
  • MICROSECOND(time) - Returning the microsecond unit value of the given time.
  • MINUTE(time) - Returning the minute unit value of the given time.
  • MONTH(date) - Returning the month unit value of the given date.
  • MONTHNAME(date) - Returning the month name of the given date.
  • NOW() - Returning the current date and time.
  • SECOND(time) - Returning the second unit value of the given time.
  • SEC_TO_TIME(seconds) - Converting a second value to a time
  • STR_TO_DATE(str,format) - Converting a character string to a date.
  • SUBDATE(date,INTERVAL expr unit) - Subtracting days from a date.
  • SUBTIME(expr1,expr2) - Subtracting a time from another time.
  • SYSDATE() - Returning current date and time.
  • TIME(expr) - Returning a time from the given date and time.
  • TIMEDIFF(expr1,expr2) - Returning the difference between two times.
  • TIME_TO_SEC(time) - Converting a time to a second value.
  • WEEKDAY(date) - Returning the weekday unit value of a given date.
  • YEAR(date) - Returning the year unit value of a given date.

(Continued on next topic...)

  1. What Are Date and Time Data Types?
  2. How To Write Date and Time Literals?
  3. How To Enter Microseconds in SQL Statements?
  4. How To Convert Dates to Character Strings?
  5. How To Convert Character Strings to Dates?
  6. What Are Date and Time Intervals?
  7. How To Increment Dates by 1?
  8. How To Decrement Dates by 1?
  9. How To Calculate the Difference between Two Dates?
  10. How To Calculate the Difference between Two Time Values?
  11. How To Present a Past Time in Hours, Minutes and Seconds?
  12. How To Extract a Unit Value from a Date and Time?
  13. What Are Date and Time Functions?
  14. What Is TIMESTAMP Data Type?
  15. How Many Ways to Get the Current Time?

MySQL Tutorials:

More...


Other Tutorials/FAQs:

More...


Related Resources:

More...


Selected Jobs:

More...