MySQL LOCALTIME or Localtime() are the Date Functions, which are used to return the current date and time in YYYY-MM-DD HH:MM:SS.
In this article, we will show you, How to use these Localtime function in MySQL to get local Date and Time with example.
MySQL LOCALTIME Syntax
The basic syntax of the local date and time in MySQL is as shown below:
TIP: Both these functions are the synonyms of NOW() function. All these three functions will return the same output.
MySQL LOCALTIME Example
The following statements shows you, how to use these MySQL local time functions.
As you can see, the above three statements returns the local date and time in YYYY-MM-DD HH:MM:SS format.
Below statements show you, what happens when add few seconds to the MySQL localtime() function.
SELECT LOCALTIME() + 2;
SELECT LOCALTIME + 22;
SELECT DATEDIFF(LOCALTIME, '2019-01-22');
From the above screenshot, you can see that, the function added those extra seconds and displaying the date in string format i.e., YYYYMMDDHHMMSS
Within the Last statement, we used the Datediff function to find the difference between the local date and time and custom date ‘2019-01-22’
Thank You for Visiting Our Blog