Home  >  Article  >  Database  >  What will MySQL return if we use the UNIX_TIMESTAMP() function without parameters?

What will MySQL return if we use the UNIX_TIMESTAMP() function without parameters?

PHPz
PHPzforward
2023-09-17 12:13:021106browse

如果我们使用不带参数的 UNIX_TIMESTAMP() 函数,MySQL 将返回什么?

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

For example, if we run a UNIX_TIMESTAMP() query with no value and using NOW() as parameter MySQL returns the same results.

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)

This can be verified by passing the results of the above query as a parameter to the FROM_UNIXTIME() function. MySQL will return the current timestamp value as shown below -

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

The above is the detailed content of What will MySQL return if we use the UNIX_TIMESTAMP() function without parameters?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete