1

我可以在 Cache SQL 中使用什么函数(类似于 ObjectScript 中的 ZDATETIME())将纪元时间戳的秒数转换为 UTC 时间戳?我查看了文档,只能找到有关在对象脚本中执行此操作的信息...您可以在 SQL 中使用什么函数?谢谢!

4

2 回答 2

2

我认为您正在寻找这样的东西;

DECLARE @epoch INT
SET @epoch = 1348519792
SELECT DATEADD(MINUTE, DATEDIFF(MINUTE, GETUTCDATE(), GETDATE()), DATEADD(s, @epoch, '19700101 00:00:00:000'))

SQL小提琴

于 2012-09-24T20:48:02.300 回答
0

想通了,我不得不手动转换它。我花了很长时间试图找到一个预先存在的功能,但我是这样做的:

select 
    TO_CHAR(substr(audit.stamp,1,5),'YYYY-MM-DD') AS Date,
    CASE LEN(CAST(substr(audit.stamp,7)/3600 AS INT))
    WHEN 2 THEN CAST(substr(audit.stamp,7)/3600 AS INT)
    ELSE '0' || CAST(substr(audit.stamp,7)/3600 AS INT)
    END || ':' ||
    CASE LEN(CAST((substr(audit.stamp,7)/60)#60 AS INT))
    WHEN 2 THEN CAST((substr(audit.stamp,7)/60)#60 AS INT)
    ELSE '0' || CAST((substr(audit.stamp,7)/60)#60 AS INT)
    END || ':' ||
    CASE LEN(CAST(substr(audit.stamp,7)#60 AS INT))
    WHEN 2 THEN CAST(substr(audit.stamp,7)#60 AS INT)
    ELSE '0' || CAST(substr(audit.stamp,7)#60 AS INT)
    END AS Time
from utility.audit

取自缓存 SQL 参考手册:

CLOCKTIME    
  NEW
  SET Time=$PIECE($HOROLOG,",",2)
  SET Sec=Time#60
  SET Totmin=Time\60
  SET Min=Totmin#60
  SET Milhour=Totmin\60
  IF Milhour=12 { SET Hour=12,Meridian=" pm" }
  ELSEIF Milhour>12 { SET Hour=Milhour-12,Meridian=" pm" }
  ELSE { SET Hour=Milhour,Meridian=" am" }
  WRITE !,Hour,":",Min,":",Sec,Meridian
  QUITCLOCKTIME    
  NEW
  SET Time=$PIECE($HOROLOG,",",2)
  SET Sec=Time#60
  SET Totmin=Time\60
  SET Min=Totmin#60
  SET Milhour=Totmin\60
  IF Milhour=12 { SET Hour=12,Meridian=" pm" }
  ELSEIF Milhour>12 { SET Hour=Milhour-12,Meridian=" pm" }
  ELSE { SET Hour=Milhour,Meridian=" am" }
  WRITE !,Hour,":",Min,":",Sec,Meridian
  QUIT

谢谢!

于 2012-09-26T20:40:03.837 回答