Có 3 cách lấy timestamp: current_timestamp, now(), current_timestamp().
Trường hợp 1 – Dùng current_timestamp()
mysql> SELECT CURRENT_TIMESTAMP();
Kết quả:
+---------------------+ | CURRENT_TIMESTAMP() | +---------------------+ | 2018-11-29 16:09:31 | +---------------------+ 1 row in set (0.00 sec)
Trường hợp 2 – Dùng now()
mysql> select now();
Kết quả:
+---------------------+ | now() | +---------------------+ | 2018-11-29 16:09:38 | +---------------------+ 1 row in set (0.00 sec)
Lấy UNIX timestamp (số nguyên):
mysql> select unix_timestamp();
Kết quả:
+------------------+ | unix_timestamp() | +------------------+ | 1543488374 | +------------------+ 1 row in set (0.04 sec)