当前位置:网站首页>金仓数据库KingbaseES 插件kdb_date_function
金仓数据库KingbaseES 插件kdb_date_function
2022-07-03 04:15:00 【沉舟侧畔千帆过_】
1. kdb_date_function介绍
kdb_date_function是一个兼容mysql数据库date相关函数的扩展。
使用时需要create extension kdb_date_function,不需要时drop extension kdb_date_function即可。
2. date_add
date_add — 实现日期的相加
语法:
date_add(ts timestamp, iv interval) 返回 timestamp。 date_add(tstz timestamptz, iv interval) 返回 timestamptz。
描述:
date_add会实现timestamp或timestamptz与指定的interval进行相加的运算。
参数:
iv
用于日期相加运算中的interval类型值。
ts
用于日期相加运算中的timestamp类型值。
tstz
用于日期相加运算中的timestamptz类型值。
返回值:
返回计算完成的特定的日期类型值。
注解:
举例:
select date_add('2000-10-10'::timestamp,interval '1 year');
date_add
--------------------------
Wed Oct 10 00:00:00 2001
(1 row)
select date_add('2010-10-10 12:00:00'::timestamp,interval '1 year 1 day 2 hour');
date_add
--------------------------
Tue Oct 11 14:00:00 2011
(1 row)
3. dateadd
dateadd — 实现日期的相加
语法:
dateadd(i_unit text, i_value numeric, i_date time) 返回 time。
dateadd(i_unit text, i_value numeric, i_date timestamp) 返回 timestamp。
dateadd(i_unit text, i_value numeric, i_date timestamptz) 返回 timestamptz。
描述:
实现timestamp或timestamptz或time类型与指定的格式进行相加的运算。
参数:
i_unit
指定要相加的i_value的格式。
i_value
指定要相加的数量。
i_date
指定被相加的日期。
返回值:
返回计算完成的特定的日期类型值。
注解:
i_unit的值可以使'second','minute','hour','day','week','month','year'等。
举例:
SELECT dateadd(year,9998,'0001-01-01 00:00:00'::timestamptz);
dateadd
------------------------------
Fri Jan 01 00:00:00 9999 PST
(1 row)
SELECT dateadd(year,201,'1900-01-01 00:00:00'::timestamptz);
dateadd
------------------------------
Sat Jan 01 00:00:00 2101 PST
(1 row)
SELECT dateadd(year,30,'1970-01-01 00:00:00'::timestamptz);
dateadd
------------------------------
Sat Jan 01 00:00:00 2000 PST
(1 row)
SELECT dateadd(year,-9998,'9999-12-31 00:00:00'::timestamptz);
dateadd
------------------------------
Mon Dec 31 00:00:00 0001 PST
(1 row)
SELECT dateadd(year,-100,'2000-12-31 00:00:00'::timestamptz);
dateadd
------------------------------
Mon Dec 31 00:00:00 1900 PST
(1 row)
SELECT dateadd(year,-34,'2004-12-31 00:00:00'::timestamptz);
dateadd
------------------------------
Thu Dec 31 00:00:00 1970 PST
(1 row)
4. datediff
比较两个日期之间的差距
语法:
datediff(d1 date, d2 date) 返回integer。 datediff(t text, d1 date, d2 date) 返回int8。 datediff(t text, d1 time, d2 time) 返回int8。 datediff(t text, d1 timetz, d2 timetz) 返回int8。 datediff(t text, d1 timestamp, d2 timestamp) 返回int8。 datediff(t text, d1 timestamptz, d2 timestamptz) 返回int8。
描述:
比较两个日期之间的指定的text(如果存在此参数)的格式的差距。
参数:
t
指定的要返回的日期差距的格式。
d1,d2
进行比较的两个日期值。
返回值:
返回text类型指定的格式的整数值。
注解:
t的值可以使'second','minute','hour','day','week','month','year'等。
举例:
SELECT datediff('year','0001-01-01'::date,'9999-12-31'::date);
datediff
----------
9998
(1 row)
SELECT datediff('year','1900-01-01 00:00:00'::date,'2000-12-31 00:00:00'::date);
datediff
----------
100
(1 row)
SELECT datediff(month,'0001-01-01 00:00:00'::date,'9999-12-31 00:00:00'::date);
datediff
----------
119987
(1 row)
SELECT datediff(month,'1900-01-01 00:00:00'::date,'2000-12-31 00:00:00'::date);
datediff
----------
1211
(1 row)
SELECT datediff('month','0001-01-01 00:00:00'::date,'9999-12-31 00:00:00'::date);
datediff
----------
119987
(1 row)
SELECT datediff('month','1900-01-01 00:00:00'::date,'2000-12-31 00:00:00'::date);
datediff
----------
1211
(1 row)
5. date_format
得到指定日期的指定格式的值。
语法:
date_format(d timestamp, t text) 返回 text。 date_format(d timestamptz, t text) 返回 text。
描述:
返回日期类型值的text指定的格式。
参数:
t
指定的要返回的日期的格式。
d
目标格式的值。
返回值:
返回text指定的text类型的值。
注解:
t的值可以是nls_date_format类型的所有值。
举例:
select date_format('2000-10-10 12:00:00','mm-yyyy-dd hh24:mi:ss');
date_format
---------------------
10-2000-10 12:00:00
(1 row)边栏推荐
- [nlp] - brief introduction to the latest work of spark neural network
- Xrandr modifier la résolution et le taux de rafraîchissement
- MySQL timestampdiff interval
- 『期末复习』16/32位微处理器(8086)基本寄存器
- 2022 electrician (Advanced) examination papers and electrician (Advanced) examination skills
- Deep dive kotlin synergy (19): flow overview
- [Yu Yue education] reference materials of political communication science of Communication University of China
- What is the correct way to compare ntext columns with constant values- What's the right way to compare an NTEXT column with a constant value?
- Taking two column waterfall flow as an example, how should we build an array of each column
- Application of I2C protocol of STM32F103 (read and write EEPROM)
猜你喜欢

JS realizes lazy loading of pictures
![[brush questions] connected with rainwater (one dimension)](/img/21/318fcb444b17be887562f4a9c1fac2.png)
[brush questions] connected with rainwater (one dimension)

300+ documents! This article explains the latest progress of multimodal learning based on transformer

2022deepbrainchain biweekly report no. 104 (01.16-02.15)

Competitive product analysis and writing

CVPR 2022 | Dalian Institute of technology proposes a self calibration lighting framework for low light level image enhancement of real scenes

leetcode:297. 二叉树的序列化与反序列化

Interaction free shell programming
![[home push IMessage] software installation virtual host rental tothebuddy delay](/img/e7/eb20a773e4b674962f856d179a3769.jpg)
[home push IMessage] software installation virtual host rental tothebuddy delay

The 10th China Cloud Computing Conference · China Station: looking forward to the trend of science and technology in the next decade
随机推荐
类的基础语法
xrandr修改分辨率與刷新率
JS realizes the animation effect of text and pictures in the visual area
[Blue Bridge Road - bug free code] pcf8591 - code analysis of AD conversion
Competitive product analysis and writing
Js/ts bottom implementation double click event
[set theory] inclusion exclusion principle (including examples of exclusion principle)
[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
[mathematical logic] predicate logic (first-order predicate logic formula | example)
2022 Shandong Province safety officer C certificate examination questions and Shandong Province safety officer C certificate simulation examination question bank
[nlp] - brief introduction to the latest work of spark neural network
Busycal latest Chinese version
What are the Bluetooth headsets with good sound quality in 2022? Inventory of four high-quality Bluetooth headsets
CVPR 2022 | Dalian Institute of technology proposes a self calibration lighting framework for low light level image enhancement of real scenes
[NLP]—sparse neural network最新工作简述
中移物联网OneOS与OneNET入选《2021年物联网示范项目名单》
[文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN
nodejs基础:浅聊url和querystring模块
105. Detailed introduction of linkage effect realization of SAP ui5 master detail layout mode
PostgreSQL database high availability Patroni source code learning - etcd class