Home >Database >Mysql Tutorial >How to Replicate MySQL's UNIX_TIMESTAMP() in SQL Server?

How to Replicate MySQL's UNIX_TIMESTAMP() in SQL Server?

DDD
DDDOriginal
2024-12-20 12:11:13982browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn