How to resolve error 7454 when casting timestamp(6) to time(0)

Database

How to resolve error 7454 when casting timestamp(6) to time(0)

I am trying to get the time 'HH:MM:SS' from a timestamp column.

This works but the result is 'HH:MM:SS.ssssss'

SELECT CAST(CURRENT_TIMESTAMP AS TIME);

Tried this and got error 7454 DateTime field overflow

SELECT CAST(CURRENT_TIMESTAMP AS TIME(0));

Is there a way to cast timestamp to time(0) without casting to a char string first?

Database version 14.00.01.10

 

Thanks

Michael

 

1 REPLY
Enthusiast

Re: How to resolve error 7454 when casting timestamp(6) to time(0)

You can do it in this way

Using an intermediate string:

CAST(SUBSTRING(CAST(x AS CHAR(26)) FROM 1 FOR 19) AS TIMESTAMP(0))