cancel
Showing results for 
Search instead for 
Did you mean: 

Convert datetime to unix/epoch format

0 Kudos
2,523

Hi everyone,

I would like to know if there is a way to convert a datetime value stored in a variable to unix/epoch format.

I found several ways to do the opposite, but found nothing helpful on how to achieve this.

A script in a job contains a variable, say $datetimevar.

This is loaded using SQL to hold a value such as '2016/01/06 18:12:00'.

I would like to know if there is a way we can convert this value to epoch/unix format and hold it in, say $datetimevar_unix.

Any help would be appreciated.

Regards,

Sid

View Entire Topic
former_member187605
Active Contributor
0 Kudos

date_diff( to_date('19700101','YYYYMMDD'),sysdate(),'SS')

replace sysdate() with any datetime value you need

0 Kudos

Thanks Dirk,

This worked

Regards,

Sid

PavelKultyshev
Product and Topic Expert
Product and Topic Expert
0 Kudos

Not anymore, there is no date_diff function in 2025. https://help.sap.com/docs/SAP_HANA_PLATFORM/4fe29514fd584807ac9f2a04f6754767/f12b86a6284c4aeeb449e57...

You can use `SECONDS_BETWEEN('1970-01-01 00:00:00', TO_TIMESTAMP(<YOUR_COLUMN>))` instead.