openGauss SQL参考—函数和操作符:类型转换函数(4)
-
to_timestamp(double precision)
描述:把UNIX纪元转换成时间戳。
返回值类型:timestamp with time zone
示例:
openGauss=# SELECT to_timestamp(1284352323); to_timestamp ------------------------ 2010-09-13 12:32:03+08 (1 row) -
to_timestamp(string [,fmt])
描述:将字符串string按fmt指定的格式转换成时间戳类型的值。不指定fmt时,按参数nls_timestamp_format所指定的格式转换。
openGauss的to_timestamp中,
- 如果输入的年份YYYY=0,系统报错。
- 如果输入的年份YYYY<0,在fmt中指定SYYYY,则正确输出公元前绝对值n的年份。
fmt中出现的字符必须与日期/时间格式化的模式相匹配,否则报错。
返回值类型:timestamp without time zone
示例:
openGauss=# SHOW nls_timestamp_format; nls_timestamp_format ---------------------------- DD-Mon-YYYY HH:MI:SS.FF AM (1 row) openGauss=# SELECT to_timestamp('12-sep-2014'); to_timestamp --------------------- 2014-09-12 00:00:00 (1 row)openGauss=# SELECT to_timestamp('12-Sep-10 14:10:10.123000','DD-Mon-YY HH24:MI:SS.FF'); to_timestamp ------------------------- 2010-09-12 14:10:10.123 (1 row)openGauss=# SELECT to_timestamp('-1','SYYYY'); to_timestamp ------------------------ 0001-01-01 00:00:00 BC (1 row)openGauss=# SELECT to_timestamp('98','RR'); to_timestamp --------------------- 1998-01-01 00:00:00 (1 row)openGauss=# SELECT to_timestamp('01','RR'); to_timestamp --------------------- 2001-01-01 00:00:00 (1 row) -
to_timestamp(text, text)
描述:将字符串类型的值转换为指定格式的时间戳。
返回值类型:timestamp
示例:
openGauss=# SELECT to_timestamp('05 Dec 2000', 'DD Mon YYYY'); to_timestamp --------------------- 2000-12-05 00:00:00 (1 row)

浙公网安备 33010602011771号