MySQL TIMESTAMP() Function

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

MySQL TIMESTAMP Function

MySQL TIMESTAMP() function is used to return a DateTime value based on the passed argument in the function.

Syntax of MySQL TIMESTAMP Function

The syntax of this timestamp() function; as follows:

TIMESTAMP(expr)
==========================
TIMESTAMP(expr1,expr2)

The first argument (expr and expr1) is a date or datetime expression. If you provide two agruments in this function, in that case, expr is added to exp1.

Example 1 – MySQL TIMESTAMP Function

Let’s take a simple example of the mysql timestamp() function; as follows:

SELECT TIMESTAMP('2019-07-21');

Output-1

+-------------------------+
| TIMESTAMP('2019-07-21') |
+-------------------------+
| 1999-12-31 00:00:00     |
+-------------------------+

Example 2 – MySQL TIMESTAMP Function

Let’s take a second example of MySQL TIMESTAMP() function with the date and time value; as follows:

SELECT TIMESTAMP('2019-07-21 23:59:59');

Output-2

+----------------------------------+
| TIMESTAMP('2019-07-21 23:59:59') |
+----------------------------------+
|  2019-07-21 23:59:59             |
+----------------------------------+

Example 3 – MySQL TIMESTAMP Function with Fractional Seconds

Let’s take an example using MySQL timestamp() function with fractional seconds part up to microseconds (6 digits); as follows:

SELECT TIMESTAMP('2019-07-21 23:59:59.999999');

Output-3

+-----------------------------------------+
| TIMESTAMP('2019-07-21 23:59:59.999999') |
+-----------------------------------------+
|  2019-07-21 23:59:59.999999             |
+-----------------------------------------+

Example 4 – MySQL TIMESTAMP Function with Two Argument

Let’s take an example using two arguments with MySQL timestamp() function; as follows:

SELECT TIMESTAMP('2019-10-31', '12:30:45');

Output-4

+-------------------------------------+
| TIMESTAMP('2019-10-31', '12:30:45') |
+-------------------------------------+
|  2019-10-31 12:30:45                |
+-------------------------------------+

Conclusion

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

Be First to Comment

Leave a Reply

Your email address will not be published.