Collections:
UNIX_TIMESTAMP() - Calculating Unix Timestamp
How to calculate the Unix timestamp from a given datetime value using the UNIX_TIMESTAMP() function?
✍: FYIcenter.com
UNIX_TIMESTAMP(datetime) is a MySQL built-in function that
calculates the Unix timestamp from a given datetime value.
For example:
SELECT UNIX_TIMESTAMP(), UNIX_TIMESTAMP('2025-11-13 10:20:19.012');
-- +------------------+-------------------------------------------+
-- | UNIX_TIMESTAMP() | UNIX_TIMESTAMP('2025-11-13 10:20:19.012') |
-- +------------------+-------------------------------------------+
-- | 1700105959 | 1763047219.012 |
-- +------------------+-------------------------------------------+
SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00');
-- +---------------------------------------+
-- | UNIX_TIMESTAMP('1970-01-01 00:00:00') |
-- +---------------------------------------+
-- | 18000 |
-- +---------------------------------------+
SELECT @@system_time_zone, 18000/60/60;
-- +--------------------+-------------+
-- | @@system_time_zone | 18000/60/60 |
-- +--------------------+-------------+
-- | EST | 5.00000000 |
-- +--------------------+-------------+
Reference information of the UNIX_TIMESTAMP() function:
UNIX_TIMESTAMP(datetime): sec
Returns the value of the argument as seconds since
'1970-01-01 00:00:00' UTC.
Arguments, return value and availability:
datetime: Optional. Default is current datetime. The datetime value
to be converted.
sec: Return value. The number of seconds between '1970-01-01 00:00:00'
and the given datetime.
Available since MySQL 4.
Related MySQL functions:
⇒ UTC_DATE() - Current UTC Date
⇐ TO_SECONDS() - Converting Datetime to seconds
2023-11-17, 1282🔥, 0💬
Popular Posts:
How To Convert a Unicode Strings to Non-Unicode Strings in SQL Server Transact-SQL? Since Unicode ch...
How To Select All Columns of All Rows from a Table in Oracle? The simplest query statement is the on...
How To Create a Dynamic Cursor with the DYNAMIC Option in SQL Server Transact-SQL? If the underlying...
What Happens If the Imported Table Already Exists in Oracle? If the import process tries to import a...
How To Get Year, Month and Day Out of DATETIME Values in SQL Server Transact-SQL? You can use DATEPA...