简体   繁体   中英

ORACLE Convert the long millisecond into Date

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?

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM