How to get timestamp using MySQL?

MySQLMySQLi Database

You can get timestamp with the help of current_timestamp, now() and current_timestamp().

Case 1 − Using current_timestamp()

The query is as follows −

mysql> SELECT CURRENT_TIMESTAMP();

The following is the output displaying timestamp −

+---------------------+
| CURRENT_TIMESTAMP() |
+---------------------+
| 2018-11-29 16:09:31 |
+---------------------+
1 row in set (0.00 sec)

Case 2 − Using now()

The query is as follows −

mysql> select now();

The following is the output −

+---------------------+
| now()               |
+---------------------+
| 2018-11-29 16:09:38 |
+---------------------+
1 row in set (0.00 sec)

You can get integer UNIX timestamp with the help of below query −

mysql> select unix_timestamp();

The following is the output −

+------------------+
| unix_timestamp() |
+------------------+
| 1543488374       |
+------------------+
1 row in set (0.04 sec
raja
Published on 10-Jan-2019 07:24:06
Advertisements