MySQL LOCALTIMESTAMP() Function

MySQL LOCALTIMESTAMP() function; In this tutorial, i am going to show you MySQL LOCALTIMESTAMP() function with the help of examples.

Mysql LOCALTIMESTAMP() Function

MySQL LOCALTIMESTAMP() function is used to return the current date and time in the format of “YYYY-MM-DD HH-MM-SS” (string) or as YYYYMMDDHHMMSS.

Syntax of Mysql LOCALTIMESTAMP() Function

The basic syntax of this function is:

 LOCALTIMESTAMP
==========================OR===============
 LOCALTIMESTAMP(optional) 

Here (optional) the parameter specifies the partial second precision for the return value.

Example 1 – Mysql LOCALTIMESTAMP() Function

Let’s take a an example using MySQL LOCALTIMESTAMP function; as follows:

SELECT LOCALTIMESTAMP;

Output-1

+---------------------+
| LOCALTIMESTAMP      |
+---------------------+
| 2019-07-19 11:35:45 |
+---------------------+

Example 2 – Mysql LOCALTIMESTAMP() Function

Let’s take an example using the LOCALTIMESTAMP() function in a numeric context; as follows:

SELECT LOCALTIMESTAMP() + 0;

Output-2

+-------------------------+
| LOCALTIMESTAMP() + 0 |
+-------------------------+
|          20190719113258 |
+-------------------------+

Example 3 – Mysql LOCALTIMESTAMP() with Now() Function

Let’s take an example using LOCALTIMESTAMP() function and NOW() function. It will return the same result(date and time); as follows:

SELECT LOCALTIMESTAMP()
       NOW();

Output-3

+-------------------------+-------------------------+ 
| LOCALTIMESTAMP()     |            NOW()        | 
+-------------------------+-------------------------+  
|     2019-07-19 11:35:45 |    2019-07-19 11:35:45  | 
+-------------------------+-------------------------+  

Example 4 – Mysql LOCALTIMESTAMP() Function

Use the following query to insert the current date into a DATETIME Field in a MySQL Database using LOCALTIMESTAMP() of MySQL; as follows:

INSERT INTO table_name SET column = LOCALTIMESTAMP

===============================OR============================

INSERT INTO test (created_at) VALUE (LOCALTIMESTAMP());

Conclusion

Mysql LOCALTIMESTAMP() Function tutorial, you have learned how to use MySQL LOCALTIMESTAMP () function with various examples.

Be First to Comment

Leave a Reply

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