Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Convert SQL datetime to date or timestamp

0 Kudos

Hi experts,

I got the value "1552895432011" of datetime field(createdAt) from SaaS, how to convert to date or timestamp using SQL ?

to_date(createdAt) , to_timstamp(createdAt) not worked.

Tks.

  • SAP Managed Tags:
4 REPLIES 4

sap_user1234
Explorer
0 Kudos

Can you please elaborate what is the actual timestamp for '1552895432011' ?

  • SAP Managed Tags:

yannmiquel
Participant
0 Kudos

Hi,

You have epoch time as an input. Its the time in second since 1970. So the reverse formula is

SELECT ADD_SECONDS(to_timestamp('1970-01-01'), 1552895432011/1000 -- or "createdAt"
)
FROM DUMMY

Best regards,

Yann

PS : Please edit you title as "convert epoch to timestamp" 🙂

Edit: corrected after reviewed by Matija

  • SAP Managed Tags:

mgregur
Active Contributor

Hi yannmiquel,

You detected correctly that it's Epoch, but the correct formula would be

SELECT ADD_SECONDS(to_timestamp('1970-01-01'), (1552895432011/1000)) -- or "createdAt"/1000
FROM DUMMY

This is because this Epoch time is calculated in miliseconds (13 digits), so you need to divide the input with 1000.

BR,

Matija

  • SAP Managed Tags:

0 Kudos

Kudos 🙂

  • SAP Managed Tags: