Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Convert Datetime to Unix Timestamp in SQL (MySQL)

How to convert Datetime to Unix timestamp in SQL (MySQL)

🎈 🎈 🎈
+1

    SELECT UNIX_TIMESTAMP('2021-02-14 23:26:58') AS unix_timestamp;
        

Output:
------------------ | unix_timestamp | ------------------ | 1613345218 |
Example only. There may be multiple ways to perform this operation.

Code Explanation

This SQL query uses the built-in MySQL function UNIX_TIMESTAMP() to convert a given date and time (in the format 'YYYY-MM-DD HH:MM:SS') to a Unix timestamp, which is the number of seconds since January 1, 1970 (the Unix epoch). The function computes the difference between the specified date (2021-02-14 23:26:58) and the Unix epoch and returns the result in seconds.
In this case, the query will output the Unix timestamp and display it under the alias 'unix_timestamp'.


Other useful SQL (MySQL) date functions

Function Description Example
NOW() Returns the current date and time in the format 'YYYY-MM-DD HH:MM:SS'. NOW() returns 2024-08-28 12:34:56
CURDATE() Returns the current date in the format 'YYYY-MM-DD'. CURDATE() returns 2024-08-28
CURTIME() Returns the current time in the format 'HH:MM:SS'. CURTIME() returns 12:34:56
UNIX_TIMESTAMP() Returns the current Unix timestamp or the Unix timestamp for a given date. UNIX_TIMESTAMP('2023-08-24 00:00:00') returns 1692835200
DATE_ADD(date, INTERVAL expr unit) Adds a specified time interval to a date. DATE_ADD('2023-08-24', INTERVAL 5 DAY) returns 2023-08-29
DATE_SUB(date, INTERVAL expr unit) Subtracts a specified time interval from a date. DATE_SUB('2023-08-24', INTERVAL 3 MONTH) returns 2023-05-24
DATEDIFF(date1, date2) Returns the difference in days between two dates. DATEDIFF('2023-08-24', '2023-01-01') returns 235
STR_TO_DATE(str, format) Parses a string into a date according to the specified format. STR_TO_DATE('24-08-2023', '%d-%m-%Y') returns 2023-08-24
DATE_FORMAT(date, format) Formats a date according to a specified format string. DATE_FORMAT('2023-08-24', '%W %M %d %Y') returns Thursday August 24 2023
Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder