Localtime() Function Examples – MySQL

Here, you will learn what is localtime() function of MySQL and how to use this function. Learn uses of these functions with various examples.

MySQL  LOCALTIME() Function

In MySQL, The LOCALTIME() function is used to returns the current date and time. This function is a synonym for the NOW() 

Note: it will be returned in ‘YYYY-MM-DD HH:MM:SS’ or YYYYMMDDHHMMSS format values, depending on whether the function is used in a string or numeric context.

Syntax

The syntax of localtime is:

LOCALTIME

====================================

LOCALTIME(optional)

Here the (optional) the argument specifies the fractional seconds precision for the return value.

Example-1

Let’s take an example for better demonstration of localtime() function

SELECT LOCALTIME;

Output-1

+---------------------+
| LOCALTIME           |
+---------------------+
| 2019-07-19 15:22:45 |
+---------------------+

Example-2

Let’s take the second example with an optional argument to specify the fractional seconds precision for the return value.

SELECT LOCALTIME(6);

Output-2

+----------------------------+
| LOCALTIME(6)               |
+----------------------------+
| 2019-07-19 15:23:23.380839 |
+----------------------------+

Example-3

Now we take an example with numeric context.

SELECT LOCALTIME + 0;

Output-3

+----------------+
| LOCALTIME + 0  |
+----------------+
| 20180628152338 |
+----------------+

Example-4

Take the last example with a nonzero or with zero value.

SELECT 
    LOCALTIME + 0,
    LOCALTIME + 4;

Output-4

+----------------+----------------+
| LOCALTIME + 0  | LOCALTIME + 5  |
+----------------+----------------+
| 20190720015212 |  20190720015216|
+----------------+----------------+

Conclusion

Here, you have learned how to use MySQL LOCALTIME() function with various examples.

If you have any questions or thoughts to share, use the comment form below to reach us.

Spread the love

Be First to Comment

Leave a Reply

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