ORACLE Convert the long millisecond into Date

百般思念 提交于 2019-12-11 06:17:38

问题


I have a Field in ORACLE as CREATED (NUMBER). It stores the time in MILLISECONDS or you can say long format. Now the requirement is to find the data between two dates using the Field CREATED.

I have the following below query which is working for where condition, but not for between condition:

SELECT date'1970-01-01' + TIMECREATED / 1000 / 60 / 60 / 24 as timet 
FROM XXX_TABLE WHERE ITBD='829993';

Can someone provide me the SQL to get the data between two dates?


回答1:


Playing with Oracle Date literals, timestamps and day-to-second intervals:

You can try something of this kind:

select *
  from the_table where to_timestamp(the_date_column,'DD/MM/YYYY') - date'1970-01-01'
                 between numtodsinterval(first_created/1000,'second') and numtodsinterval(second_created/1000,'second')

or

select *
  from the_table
 where date'1970-01-01' + numtodsinterval(created/1000,'second')
       between to_timestamp('2011-01-01','YYYY-MM-DD')
           and to_timestamp('2012-01-01','YYYY-MM-DD')


来源:https://stackoverflow.com/questions/9483465/oracle-convert-the-long-millisecond-into-date

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!