MySQL LOCALTIME() function
LOCALTIME() function
MySQL LOCALTIME returns the value of current date and time in ‘YYYY-MM-DD HH:MM:SS’ format or YYYYMMDDHHMMSS.uuuuuu format depending on the context (numeric or string) of the function. CURRENT_TIMESTAMP, CURRENT_TIMESTAMP(), NOW, NOW(), LOCALTIME(), LOALTIMESTAMP, LOCALTIMESTAMP() are the synonyms of LOCALTIME. The LOCALTIME returns the constant time when the statement began to work.
Note : Output of the examples of this page will depend on the current time.
This function is useful in -
- The function enables time-based calculations and comparisons using the current local time.
- LOCALTIME() is useful for logging activities and events with the exact local time at which they occurred.
- The function is used in user interfaces to display the current local time to users, providing real-time information.
- In applications that involve event scheduling or timing, LOCALTIME() helps ensure accurate timing of events.
- The function is used to generate timestamp values that represent the current local time.
- In systems that need to align processes with the local time, LOCALTIME() ensures that actions occur at the correct local time.
Syntax:
LOCALTIME;
Syntax Diagram:
MySQL Version: 8.0
Pictorial Presentation:
Example : MySQL LOCALTIME
The following statement will return the current date and time in ‘YYYY-MM-DD HH:SS:MM’ format.
Code:
SELECT LOCALTIME;
Output:
mysql> SELECT LOCALTIME; +---------------------+ | LOCALTIME | +---------------------+ | 2015-04-13 17:02:09 | +---------------------+ 1 row in set (0.01 sec)
Example : LOCALTIME in numeric format
The following statement will return the current date and time in ‘YYYY-MM-DD HH:SS:MM’ format as well as YYYYMMDDHHSSMM.uuuuuu format.
Code:
SELECT LOCALTIME,LOCALTIME+1;
Output:
mysql> SELECT LOCALTIME,LOCALTIME+1; +---------------------+-----------------------+ | LOCALTIME | LOCALTIME+1 | +---------------------+-----------------------+ | 2015-04-13 17:04:24 | 20150413170425.000000 | +---------------------+-----------------------+ 1 row in set (0.02 sec)
Example: LOCALTIME()
The following statement will return the current date and time in ‘YYYY-MM-DD HH:SS:MM’ format.
Code:
SELECT LOCALTIME();
Output:
mysql> SELECT LOCALTIME(); +---------------------+ | LOCALTIME() | +---------------------+ | 2015-04-13 17:06:19 | +---------------------+ 1 row in set (0.01 sec)
Example: LOCALTIME() in numeric format
The following statement will return the current date and time in ‘YYYY-MM-DD HH:SS:MM’ format as well as YYYYMMDDHHSSMM.uuuuuu format.
Code:
SELECT LOCALTIME(),LOCALTIME()+1;
Output:
mysql> SELECT LOCALTIME(),LOCALTIME()+1; +---------------------+-----------------------+ | LOCALTIME() | LOCALTIME()+1 | +---------------------+-----------------------+ | 2015-04-13 17:08:12 | 20150413170813.000000 | +---------------------+-----------------------+ 1 row in set (0.00 sec)
Video Presentation:
All Date and Time Functions:
Click here to see the MySQL Date and time functions.
Previous: LAST_DAY()
Next: LOCALTIMESTAMP()
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/mysql/date-and-time-functions/mysql-localtime-function.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics