当前位置:网站首页>金仓数据库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)边栏推荐
- [untitled] 2022 safety production supervisor examination question bank and simulated safety production supervisor examination questions
- 基于Pytorch和RDKit的QSAR模型建立脚本
- [brush questions] most elements (super water king problem)
- [Blue Bridge Road - bug free code] pcf8591 - code analysis of AD conversion
- Leecode swipe questions and record LCP 18 breakfast combination
- Competitive product analysis and writing
- Design and implementation of kubelet garbage collection mechanism to protect nodes from being preempted by containers image GC high threshold
- xrandr修改分辨率與刷新率
- What are the Bluetooth headsets with good sound quality in 2022? Inventory of four high-quality Bluetooth headsets
- Sklearn data preprocessing
猜你喜欢

Five elements of user experience

有监督预训练!文本生成又一探索!

"Final review" 16/32-bit microprocessor (8086) basic register

IPv6 foundation construction experiment

【刷题篇】多数元素(超级水王问题)
![[Apple Photo Album push] IMessage group anchor local push](/img/a7/6a27d646ecba0d7c93f8dac38492a2.jpg)
[Apple Photo Album push] IMessage group anchor local push

JS realizes the animation effect of text and pictures in the visual area

The time has come for the domestic PC system to complete the closed loop and replace the American software and hardware system

China Mobile Internet of things oneos and onenet were selected in the list of 2021 Internet of things demonstration projects

MPLS setup experiment
随机推荐
因果AI,下一代可信AI的产业升级新范式?
基于Pytorch和RDKit的QSAR模型建立脚本
[set theory] set concept and relationship (set represents | number set | set relationship | contains | equality | set relationship property)
Social phobia of contemporary young people (III)
How to connect WiFi with raspberry pie
How to execute a swift for in loop in one step- How can I do a Swift for-in loop with a step?
[mathematical logic] predicate logic (first-order predicate logic formula | example)
Practical operation of vim
[Blue Bridge Road -- bug free code] interpretation of some codes of matrix keyboard
[mathematical logic] predicate logic (toe normal form | toe normal form conversion method | basic equivalence of predicate logic | name changing rules | predicate logic reasoning law)
CVPR 2022 | Dalian Technology propose un cadre d'éclairage auto - étalonné pour l'amélioration de l'image de faible luminosité de la scène réelle
DAPP for getting started with eth
eth入门之简介
[nlp] - brief introduction to the latest work of spark neural network
JS native common knowledge
中移物联网OneOS与OneNET入选《2021年物联网示范项目名单》
竞品分析撰写
Causal AI, a new paradigm for industrial upgrading of the next generation of credible AI?
解决bp中文乱码
Interaction free shell programming