MySQL Dates and Times Functions Example

Home / MySQL Dates and Times Functions Example

In this post we will see MySQL dates and times related examples. As we know MySQL provide some functions using which we can get date and time and related data. As we know there are many scenario when we have to get date and time and some time we have to perform some mathematics with dates and times also so MySQL inbuilt function is very helpful in all of this . Some of the inbuilt MySQL Dates and Times functions are.

  1. now()
  2. curdate()
  3. curtime()
  4. year()
  5. month()
  6. monthname()
  7. day()
  8. dayname()
  9. dayofmonth()
  10. dayofweek()
  11. dayofyear()

1. now()

now() is a inbuilt function provided by MySQL. This function provide us current date and time of server.

2. curdate()

curdate() is a inbuilt function provided by MySQL. This function provide us current date of the server.

3. curtime()

curtime() is a inbuilt function provided by MySQL. This function provide us current time of the server.

date and time MySQL

4. year()

year() function is used to get the year from the current date. We can use now() and curdate() function with year() to fetch the year.

year() in MySQL

5. month()

This function is used to get the month from the current date of server.

6. monthname()

This function is used to get the name of month from the current date of server.

mont() in MySQL

7. day()

This function is used to get the day from the current date of server. There are many other functions for getting details of day and that are dayname(), dayofmonth(), dayofweek(), dayofyear().

day() in MySQL

You may also like :

How to take databackup in MySQL using commandLine.

MySQL Basic Commands.

Reference :

MySQL official Document for Dates and Times

Help Others, Please Share

About Author

Leave a Reply

Your email address will not be published. Required fields are marked *