Home >Database >Mysql Tutorial >How to Replicate MySQL's UNIX_TIMESTAMP() in SQL Server?
Translating MySQL's UNIX_TIMESTAMP() to SQL Server
In need of replicating the functionality of MySQL's UNIX_TIMESTAMP() in SQL Server 2008? Here's how to achieve it:
For Simple Date Conversion (No Pre-1970 or Millisecond Concerns):
SELECT DATEDIFF(s, '1970-01-01 00:00:00', DateField)
For Millisecond Precision (SQL Server 2016 and Above):
SELECT DATEDIFF_BIG(ms, '1970-01-01 00:00:00', DateField)
These methods provide a close approximation to MySQL's built-in UNIX_TIMESTAMP() function for converting dates to epoch time in SQL Server.
The above is the detailed content of How to Replicate MySQL's UNIX_TIMESTAMP() in SQL Server?. For more information, please follow other related articles on the PHP Chinese website!