cancel
Showing results for 
Search instead for 
Did you mean: 

Convert in hana

Former Member
0 Kudos

Hi all,

How to convert a TIMESTAMP to BIGINT in HANA studio?

Accepted Solutions (1)

Accepted Solutions (1)

lbreddemann
Active Contributor
0 Kudos

Do you realise that the conversion from a date data type into an integer is not a standardised operation?

MS SQL Server clearly does that differently and that's fine.

There is no standard for that.

If you have a specific use case in mind that requires the result to be like the one from SQL Server, then you might need to write your own little function for that. It's not that difficult.

My guess would be that SQL Server returns the number of days since 1st January 1901 for their cast to an integer.

You can emulate that very easily in SAP HANA by using the add_days() function:

select days_between('1900-01-01', '2017-02-22') from dummy;
DAYS_BETWEEN('1900-01-01','2017-02-22')
42786

There you go.

Happy with that?

It's important to understand, what the functions actually do and which ones are standard and which ones are vendor specific.

Answers (1)

Answers (1)

lbreddemann
Active Contributor
0 Kudos
select
    tstmp_from_seconddate(current_timestamp)
from dummy;
TSTMP_FROM_SECONDDATE(CURRENT_TIMESTAMP) 
20170221092514                          

This should do the trick...

Former Member
0 Kudos

Hi Lars,

Thank you for reply,

You'r answer is true, but this result isn't equal with SQL result.

Please see sample:

SQL:

select getdate() --result: 2017-02-22 11:31:00.787
select cast(getdate() as bigint) --result: 42786

HANA:

select (current_timestamp)from dummy; --result: Feb 22, 2017 11:37:20.095 AM

select tstmp_from_seconddate(current_timestamp) from dummy; --result:20,170,222,113,720

Former Member
0 Kudos

Thanks lars;

I changed my function and solved my problem by another way.

lbreddemann
Active Contributor
0 Kudos

you might as well accept the answer instead of closing the question for "other" reasons.