Skip to Content
avatar image
-1
Former Member

Convert in hana

Hi all,

How to convert a TIMESTAMP to BIGINT in HANA studio?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Feb 22, 2017 at 11:10 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 21, 2017 at 09:26 AM
    select
        tstmp_from_seconddate(current_timestamp)
    from dummy;
    
    TSTMP_FROM_SECONDDATE(CURRENT_TIMESTAMP) 
    20170221092514                          

    This should do the trick...

    Add comment
    10|10000 characters needed characters exceeded