sql – 将Datetime转换为Unix时间戳

栏目: 数据库 · 发布时间: 7年前

内容简介:在Microsoft SQL Server 2012或更高版本中,是否可以在单个select语句中将datetime值转换为Unix时间戳?如果是这样,怎么办呢?翻译自:https://stackoverflow.com/questions/34455408/convert-datetime-to-unix-timestamp

在Microsoft SQL Server 2012或更高版本中,是否可以在单个select语句中将datetime值转换为Unix时间戳?如果是这样,怎么办呢?

将日期时间转换为unix时间戳很容易,但是容易出错,请输入以下内容:

@timestamp=DATEDIFF(second,{d '1970-01-01'},@datetime)

其中@datetime是您要转换的日期时间值.

{d’yyyy-mm-dd’}表示法是ODBC转义序列.

功能:

CREATE FUNCTION UNIX_TIMESTAMP (
@ctimestamp datetime
)
RETURNS integer
AS
BEGIN
  /* Function body */
  declare @return integer

  SELECT @return = DATEDIFF(SECOND,{d '1970-01-01'}, @ctimestamp)

  return @return
END

现在试试吧@Ousman:

SELECT UNIX_TIMESTAMP(GETDATE());

翻译自:https://stackoverflow.com/questions/34455408/convert-datetime-to-unix-timestamp


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Thirty-three Miniatures

Thirty-three Miniatures

Jiří Matoušek / American Mathematical Socity / 2010-6-18 / USD 24.60

This volume contains a collection of clever mathematical applications of linear algebra, mainly in combinatorics, geometry, and algorithms. Each chapter covers a single main result with motivation and......一起来看看 《Thirty-three Miniatures》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

html转js在线工具
html转js在线工具

html转js在线工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具