Hi Mahesh,
if it's correct depends on your definition, between TIMESTAMP '2011-01-10 23:01:59' and TIMESTAMP '2011-01-10 23:02:00' there is one second, but the result will be 1 minute, i.e. the same result as "end_ts - start_ts minute".
When you create it based on the seconds calculation you might get:
fractional minutes = timestamp_diff_seconds(start_ts, end_ts) / 60
truncated minutes = cast(timestamp_diff_seconds(start_ts, end_ts) / 60 as bigint)
rounded minutes = cast(timestamp_diff_seconds(start_ts, end_ts) / 60 as decimal(10,0))
You can simple nest this calculation in another UDF instead of copying/modifying the source code.
Btw, i posted a wrong version of the Timestamp_Diff_Seconds, but you already noticed that :-)
This is the correct one:
REPLACE FUNCTION TimeStamp_Diff_Seconds
(
ts1 TIMESTAMP(6)
,ts2 TIMESTAMP(6)
)
RETURNS DECIMAL(18,6)
LANGUAGE SQL
CONTAINS SQL
RETURNS NULL ON NULL INPUT
DETERMINISTIC
SQL SECURITY DEFINER
COLLATION INVOKER
INLINE TYPE 1
RETURN
(CAST((CAST(ts2 AS DATE)- CAST(ts1 AS DATE)) AS DECIMAL(18,6)) * 60*60*24)
+ ((EXTRACT( HOUR FROM ts2) - EXTRACT( HOUR FROM ts1)) * 60*60)
+ ((EXTRACT(MINUTE FROM ts2) - EXTRACT(MINUTE FROM ts1)) * 60)
+ (EXTRACT(SECOND FROM ts2) - EXTRACT(SECOND FROM ts1))
;
Dieter
Hi Mahesh,
if it's correct depends on your definition, between TIMESTAMP '2011-01-10 23:01:59' and TIMESTAMP '2011-01-10 23:02:00' there is one second, but the result will be 1 minute, i.e. the same result as "end_ts - start_ts minute".
When you create it based on the seconds calculation you might get:
fractional minutes = timestamp_diff_seconds(start_ts, end_ts) / 60
truncated minutes = cast(timestamp_diff_seconds(start_ts, end_ts) / 60 as bigint)
rounded minutes = cast(timestamp_diff_seconds(start_ts, end_ts) / 60 as decimal(10,0))
You can simple nest this calculation in another UDF instead of copying/modifying the source code.
Btw, i posted a wrong version of the Timestamp_Diff_Seconds, but you already noticed that :-)
This is the correct one:
Dieter