MySQL CURRENT TIMESTAMP Function

MySQL CURRENT TIMESTAMP Function; In this tutorial, i am going to show you MySQL current timestamp function with the help of examples.

Mysql CURRENT_TIMESTAMP() Function

In MySQL, the CURRENT_TIMESTAMP returns the current date and time in ‘YYYY-MM-DD HH:MM:SS’ format or YYYYMMDDHHMMSS. uuuuuu format depending on whether numeric or string is used in the function. NOW() and CURRENT_TIMESTAMP() are the synonym of CURRENT_TIMESTAMP

Syntax of Mysql CURRENT_TIMESTAMP() Function

The basic syntax of this function is:

 CURRENT_TIMESTAMP
==========================OR===============
 CURRENT_TIMESTAMP(optional) 

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

Example 1 – Mysql CURRENT_TIMESTAMP() Function

Let’s take a basic example of a current_timestamp function is

SELECT CURRENT_TIMESTAMP;

Output-1

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

Example 2 – Mysql CURRENT_TIMESTAMP() Function with Numeric Context

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

SELECT CURRENT_TIMESTAMP() + 0;

Output-2

+-------------------------+
| CURRENT_TIMESTAMP() + 0 |
+-------------------------+
|          20190719113258 |
+-------------------------+

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

Let’s take an example using the CURRENT_TIMESTAMP() function and NOW() function; as follows:

SELECT CURRENT_TIMESTAMP()
       NOW();

Output-3

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

Example 4 – Mysql CURRENT_TIMESTAMP() with PHP Query

Following below is the example of how to insert the current date into a DATETIME Field in a MySQL Database using current_timestamp() of MySQL.

INSERT INTO table_name SET column = CURRENT_TIMESTAMP

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

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

Example 5 – Mysql CURRENT_TIMESTAMP() with PHP Query

Following below is the example of how to insert the current date into a DATETIME column in a MySQL Database using current_timestamp() of PHP MySQL; as follows:

<?php 
    $query = "INSERT INTO table_name SET column_name = CURRENT_TIMESTAMP";
    $sqlQUERY = mysql_query($query) or die(mysql_error());
?>

Conclusion

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

Leave a Comment