What MySQL returns if we use UNIX_TIMESTAMP() function with no argument?


In that case, MySQL returns the Unix timestamp of the current date and time. Hence we can say that using no argument is same as using NOW() as an argument to UNIX_TIMESTAMP() function.

For example, if we run the query for UNIX_TIMESTAMP() with no value and with NOW() as an argument that MySQL returns the same result.

mysql> Select UNIX_TIMESTAMP();
+------------------+
| UNIX_TIMESTAMP() |
+------------------+
|       1509405559 |
+------------------+
1 row in set (0.00 sec)

mysql> Select UNIX_TIMESTAMP(NOW());
+-----------------------+
| UNIX_TIMESTAMP(NOW()) |
+-----------------------+
|            1509405559 |
+-----------------------+
1 row in set (0.00 sec)

The same can be verified by passing the result from the query above as argument to FROM_UNIXTIME() function. MySQL will return the current timestamp value as follows −

mysql> Select FROM_UNIXTIME(1509405559);
+---------------------------+
| FROM_UNIXTIME(1509405559) |
+---------------------------+
| 2017-10-31 04:49:19       |
+---------------------------+
1 row in set (0.00 sec)

Updated on: 20-Jun-2020

177 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements