MySQL Localtime() Function Example

MySQL Localtime() Function Example

MySQL Localtime() function; In this tutorial, we 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.

Recommended MySQL Tutorials

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

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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