Epoch and Unix Timestamp Conversion in MySQL
MySQL is a fast, reliable, general-purpose, relational database management system. It is an widely used for a range of applicatios, specificaly web applications. MySQL is a feature rich platform that have date time function like NOW()
, UNIX_TIMESTAMP()
, FROM_UNIXTIME()
, STR_TO_DATE()
etc. to handle epoch or Unix timestamp conversion into human readable dates or can convert human readable dates to Unix timestamp in MYSQL.
Here we will explain MySQL date time functions to get current epoch or Unix timestamp, convert timestamp to date and convert date to epoch or Unix timestamp.
Get current epoch or Unix timestamp in MySQLThere are UNIX_TIMESTAMP()
function to get unix timestamp. If UNIX_TIMESTAMP()
function called without date argument, it returns a current unix timestamp
UNIX_TIMESTAMP()
Output:
1745570129
Convert epoch or Unix timestamp to date in MySQL
We can use the FROM_UNIXTIME()
function to convert the epoch or timestamp to readable date format.
FROM_UNIXTIME(1624704627)
Output:
2025-06-26 10:50:27
Convert date to epoch or unix timestamp in MySQL
we can convert the date time string to unix timestamp using UNIX_TIMESTAMP()
and STR_TO_DATE()
function like below:
UNIX_TIMESTAMP(STR_TO_DATE('June 26 2025 10:50AM', '%M %d %Y %h:%i%p')
Output:
1745570129
More about date time in MySQL
Also, read:
- Epoch and Unix Timestamp Conversion in PHP
- Epoch and Unix Timestamp Conversion in Java
- Epoch and Unix Timestamp Conversion in JavaScript
- Epoch and Unix Timestamp Conversion in Perl
- Epoch and Unix Timestamp Conversion in Python
- Epoch and Unix Timestamp Conversion in TypeScript
- Epoch and Unix Timestamp Conversion SQL Server
- Epoch and Unix Timestamp Conversion in C# (C-Sharp)
- Epoch and Unix Timestamp Conversion in Kotlin
- Epoch and Unix Timestamp Conversion in Go
- Epoch and Unix Timestamp Conversion in Ruby
- Epoch and Unix Timestamp Conversion in VBA
- Epoch and Unix Timestamp Conversion in MATLAB
- Epoch and Unix Timestamp Conversion in Rust