Localtime() Function Examples – MySQL

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.

You may like

  1. TIMESTAMP() Function Examples – MySQL
  2. TIMEDIFF() Function Examples – MySQL
  3. SEC_TO_TIME() Function Examples – MySQL
  4. QUARTER() Function Examples – MySQL
  5. STR_TO_DATE() Function Examples – MySQL
  6. PERIOD_DIFF() Function Examples – MySQL
  7. PERIOD_ADD() Function Examples – MySQL
  8. SECOND() Function Examples – MySQL
  9. MICROSECOND() Function Examples – MySQL
  10. MAKETIME() Function Examples – MySQL
  11. CURTIME() Function Examples – MySQL
  12. MySQL CURRENT TIMESTAMP Function Examples
  13. MySQL CURRENT TIME Function Examples
  14. ADDTIME() Function Examples – MySQL
  15. MINUTE() Function Examples – MySQL
  16. HOUR() Function Examples – MySQL
  17. NOW() MySQL Function | MySQL
  18. MySQL DATE() And TIME() Functions (List)
  19. TIMESTAMPADD() Function Examples – MySQL
  20. TIMESTAMPDIFF() Function Examples – MySQL

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

Leave a Reply

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