GBase 8a获取指定日期年和周的yearweek函数介绍与样例

本文介绍GBase 8a数据库集群通过yearweek函数,获得指定日期所在的年和周的函数用法和使用样例。

语法

YEARWEEK(date)
YEARWEEK(date,mode)

说明

返回日期 date 对应的年和周。
YEARWEEK(date, mode)中的参数 mode,形式和作用与 WEEK()中 mode 参数相同。同样,如果忽略了 mode 参数,则使用系统变量 default_week_format 的值。

用例

无mode参数的采用了系统默认的模式。该功能更多的用于创建年月的分表。其中模式8和9是针对中国习惯:只要有1天在这1年,就算第一周。

gbase> show variables like 'default_week_format';
+---------------------+-------+
| Variable_name       | Value |
+---------------------+-------+
| default_week_format | 0     |
+---------------------+-------+
1 row in set (Elapsed: 00:00:00.01)

gbase> select @d,yearweek(@d),yearweek(@d,3),yearweek(@d,8);
+------------+--------------+----------------+----------------+
| @d         | yearweek(@d) | yearweek(@d,3) | yearweek(@d,8) |
+------------+--------------+----------------+----------------+
| 2021-01-01 |       202052 |         202053 |         202101 |
+------------+--------------+----------------+----------------+
1 row in set (Elapsed: 00:00:00.00)

参考

GBase 8a数据库week函数模式,获得指定日期的星期

GBase 8a的week函数模式实现每年的第1天总是第1周,哪怕就1天也算