将Unixtime转换为Datetime SQL(Oracle) [英] Convert Unixtime to Datetime SQL (Oracle)
本文介绍了将Unixtime转换为Datetime SQL(Oracle)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个datetime字段(P_DT),我想返回所有结果,其中P_DT大于输入的unix时间戳.
I have a datetime field(P_DT) and I would like to return all results where P_DT is greater then an input unix timestamp.
Oracle有任何内置功能可以提供帮助吗?
Does Oracle have any built in functions that can help?
在搜索中,我找到了DateTime到Unix的结果,但没有Unix到DateTime的结果...
In my searchs I find resuts for DateTime to Unix but no Unix to DateTime...
推荐答案
没有内置函数.但是写一个相对容易.由于Unix时间戳是自1970年1月1日以来的秒数
There are no built-in functions. But it's relatively easy to write one. Since a Unix timestamp is the number of seconds since January 1, 1970
CREATE OR REPLACE FUNCTION unix_ts_to_date( p_unix_ts IN NUMBER )
RETURN DATE
IS
l_date DATE;
BEGIN
l_date := date '1970-01-01' + p_unix_ts/60/60/24;
RETURN l_date;
END;
您可以看到它被称为
SQL> select unix_ts_to_date( 1336822620 ) from dual;
UNIX_TS_TO_DATE(133
-------------------
2012-05-12 11:37:00
这篇关于将Unixtime转换为Datetime SQL(Oracle)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文