2

I am using Redshift and am looking to extract the time from the timestamp.

Here is the timestamp: 2017-10-31 23:30:00

and I would just like to get the time as 23:30:00

Is that possible?

user8659376
  • 369
  • 4
  • 8
  • 19

2 Answers2

9

In Redshift you can simply cast the value to a time:

the_timestamp_column::time

alternatively you can use the standard cast() operator:

cast(the_timestamp_column as time)
  • tested as working using select '2017-10-31 23:30:00'::timestamp::time; returns 23:30:00 – Jon Scott Nov 02 '17 at 08:16
  • 1
    Would we be able to use this method on an entire column? When I try it, I get this error message: `Function ""time"(timestamp without time zone)" not supported.` Would I have to specify a timezone? – user8659376 Nov 03 '17 at 04:52
1

Please go through this link

http://docs.aws.amazon.com/redshift/latest/dg/r_Dateparts_for_datetime_functions.html

timezone, timezone_hour, timezone_minute

Supported by the DATE_TRUNC function and the EXTRACT for time stamp with time zone (TIMESTAMPTZ)

Examples is here

select extract(minute from timestamp '2009-09-09 12:08:43');
select extract(hours from timestamp '2009-09-09 12:08:43');
Jawad Siddiqui
  • 195
  • 1
  • 1
  • 15