如下可参考、测试:
1、------------------------------------------
•numtoday(numeric)
描述:将数字类型的值转换为指定格式的时间戳。
返回值类型:timestamp
示例:
openGauss=# SELECT numtoday(2);
numtoday
----------
2 days
(1 row)
2、------------------------------------------
•to_char(datetime/interval [, fmt])
描述:将一个DATE、TIMESTAMP、TIMESTAMP WITH TIME ZONE或者TIMESTAMP WITH LOCAL TIME ZONE类型的DATETIME或者INTERVAL值按照fmt指定的格式转换为VARCHAR类型。
◾可选参数fmt可以为以下几类:日期、时间、星期、季度和世纪。每类都可以有不同的模板,模板之间可以合理组合,常见的模板有:HH、MM、SS、YYYY、MM、DD。
◾模板可以有修饰词,常用的修饰词是FM,可以用来抑制前导的零或尾随的空白。
返回值类型:varchar
示例:
openGauss=# SELECT to_char(current_timestamp,'HH12:MI:SS');
to_char
----------
10:19:26
(1 row)
openGauss=# SELECT to_char(current_timestamp,'FMHH12:FMMI:FMSS');
to_char
----------
10:19:46
(1 row)
3、------------------------------------------
•to_char(interval, text)
描述:将时间间隔类型的值转换为指定格式的字符串。
返回值类型:text
示例:
openGauss=# SELECT to_char(interval '15h 2m 12s', 'HH24:MI:SS');
to_char
----------
15:02:12
(1 row)
4、------------------------------------------
•to_char(timestamp, text)
描述:将时间戳类型的值转换为指定格式的字符串。
返回值类型:text
示例:
openGauss=# SELECT to_char(current_timestamp, 'HH12:MI:SS');
to_char
----------
10:55:59
(1 row)
5、------------------------------------------
•to_date(text)
描述:将文本类型的值转换为指定格式的时间戳。目前只支持两类格式。
◾格式一:无分隔符日期,如20150814,需要包括完整的年月日。
◾格式二:带分隔符日期,如2014-08-14,分隔符可以是单个任意非数字字符。
返回值类型:timestamp without time zone
示例:
openGauss=# SELECT to_date('2015-08-14');
to_date
---------------------
2015-08-14 00:00:00
(1 row)
•to_date(text, text)
描述:将字符串类型的值转换为指定格式的日期。
返回值类型:timestamp without time zone
示例:
openGauss=# SELECT to_date('05 Dec 2000', 'DD Mon YYYY');
to_date
---------------------
2000-12-05 00:00:00
(1 row)
6、------------------------------------------
•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)
7、------------------------------------------
•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)
8、------------------------------------------
•abstime_text
描述:将abstime类型转为text类型输出。
参数:abstime
返回值类型:text
•abstime_to_smalldatetime
描述:将abstime类型转为smalldatatime类型。
参数:abstime
返回值类型:smalldatetime
•bpchar_date
描述:将字符串转为日期。
参数:character
返回值类型:date
•bpchar_timestamp
描述:将字符串转为时间戳。
参数:character
返回值类型:timestamp without time zone
•bpchar_to_smalldatetime
描述:将字符串转为smalldatetime。
参数:character
返回值类型:smalldatetime
•date_bpchar
描述:将date类型转换为bpchar类型。
参数:date
返回值类型:character
•date_text
描述:将date类型转换为text类型。
参数:date
返回值类型:text
•date_varchar
描述:将date类型转换为varchar类型。
参数:date
返回值类型:character varying
•float8_interval
描述:float8转换为interval。
参数:double precision
返回值类型:interval
另外,可查阅官方最新文档资料~ 欢迎补充、交流~