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
Release: 2024-12-20 12:11:13
Original
979 people have browsed it

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)
Copy after login

For Millisecond Precision (SQL Server 2016 and Above):

SELECT DATEDIFF_BIG(ms, '1970-01-01 00:00:00', DateField)
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template