How to get timestamp using MySQL?


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

Updated on: 29-Jun-2020

141 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements