Quantcast
Channel: SCN: Message List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 9165

Re: Subtract timestamps, result with fractions of seconds

$
0
0

Hi Michael,

 

currently the support for calculations of sub-seconds or fractions of seconds is rather shallow.

 

What you could do is something like this:

 

createcolumntable times (one_time timestamp, another_time timestamp);

 

insertinto times values (to_timestamp(now()),NULL);

update times set another_time = to_timestamp(now());

 

select * from times;

/*

ONE_TIME ANOTHER_TIME          

15.04.2013 10:49:17.216 15.04.2013 10:49:35.000

*/

 

select

    TO_SECONDDATE (one_time),

    TO_SECONDDATE (another_time),

   

    TO_INTEGER(TO_VARCHAR (one_time, 'FF7')) as one_time_fraction,

    TO_INTEGER(TO_VARCHAR (another_time, 'FF7')) as another_time_fraction

      

from

times;

 

/*

TO_SECONDDATE(ONE_TIME) TO_SECONDDATE(ANOTHER_TIME) ONE_TIME_FRACTION   ANOTHER_TIME_FRACTION

15.04.2013 10:49:17.000 15.04.2013 10:49:35.000     2.160.000           0                   

*/

 

I guess you could take this from here.

Anyhow, having the fraction available as an integer value is obviously just half of the story.

You would need to deal with over/underflows of the fractional seconds part yourself in your coding.

Not too nice ...

 

Maybe you'd be better off (at least for the time being) to implement your time stamps/intervals with a different data type (e.g. bigint) for data storage.

 

- Lars


Viewing all articles
Browse latest Browse all 9165

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>