Extracting Time from Timestamp in SQL

て烟熏妆下的殇ゞ 提交于 2019-12-25 18:02:13

问题


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?


回答1:


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)



回答2:


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');


来源:https://stackoverflow.com/questions/47069483/extracting-time-from-timestamp-in-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!