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

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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