2

I have a column of NUMBER(15) datatype which stores unix timestamps. I am trying to get a date and datetime from it. I have been able to get datetime from it but not a date. e.g. 1456342438 is the value i am trying to convert to date and datetime.

Either of these queries give me a DateTime:

select TO_DATE('1970-01-01','YYYY-MM-DD') + numtodsinterval(1456342438,'SECOND') from dual;

select TO_DATE('19700101000000','YYYYMMDDHH24MISS') + numtodsinterval(1456342438,'SECOND') from dual;

How can i get a date from this value?

2
  • You could cast the result to a date. Commented Feb 24, 2016 at 21:38
  • Yes, Had been trying unsuccessfully so far. TRUNC worked. Commented Feb 24, 2016 at 22:06

1 Answer 1

2
select to_date('01/01/1970','mm/dd/yyyy') + numtodsinterval(1456342438,'SECOND'), 
TRUNC(to_date('01/01/1970','mm/dd/yyyy') + numtodsinterval(1456342438,'SECOND')) from dual;

This worked.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.