CAST(timestamp AS UNSIGNED) gives YYYYMMDDhhmmss (original) original post
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
CAST(CURRENT_TIMESTAMP AS UNSIGNED) is a 14-digit number (original) original post
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
UNIX_TIMESTAMP() for seconds since 1970 (usually what is meant) modern rewrite
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
CAST of a timestamp with .654321 seconds: MySQL rounds up (…28), MariaDB truncates (…27) version check
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6≠10.11≠11.4≠11.8≠
First published 2012-04-20. The text below is the original; the table above shows how it behaves on current versions.
I have seen this question raised several times. How can we convert a timestamp to an INTEGER. This is achieved by using the CAST function available in MySQL.
Here is an example:
mysql> select cast(current_timestamp as unsigned);
+-------------------------------------+
| cast(current_timestamp as unsigned) |
+-------------------------------------+
| 20120420174927 |
+-------------------------------------+
1 row in set (0.00 sec)