全部展开/折叠
日期和时间函数
QlikView 日期和时间函数用于变换和转换日期和时间值。所有函数都可用于加载脚本和图表表达式。
这些函数基于日期-时间序列号(等于从 1899 年 12 月 30 日开始的天数)。整数部分表示天数,分数部分表示一天的时间。
QlikView 使用该参数的数值,所以数字即使没有格式化为日期或时间,也可以作为参数的有效值。例如,如果参数与数值不对应(因为它是一个字符串),则 QlikView 会尝试根据日期和时间环境变量解释此字符串。
如果在参数中使用的时间格式与环境变量设置不一致,QlikView 将不会做出正确的解释。要解决此问题,可更改设置或使用解释功能。
在每个函数的示例中,假设默认的时间和日期格式为 hh:mm:ss 和 YYYY-MM-DD (ISO 8601) 。
信息注释
使用日期或时间函数处理时间戳时,QlikView 忽略任何夏令时参数,除非日期或时间函数包含地理位置。
例如,ConvertToLocalTime( filetime('Time.qvd'), 'Paris') 将使用夏令时参数,而 ConvertToLocalTime(filetime('Time.qvd'), 'GMT-01:00') 将不使用夏令时参数。
使用每个函数的下拉列表可查看每个函数的简短描述和语法。单击语法描述中的函数名称可了解更多信息。
时间的整数表达式
second
此函数用于根据标准数字解释当 expression 小数部分被解释为时间时返回一个表示秒的整数。
second (expression )
minute
此函数用于根据标准数字解释当 expression 小数部分被解释为时间时返回一个表示分钟的整数。
minute (expression )
hour
此函数用于根据标准数字解释当 expression 小数部分被解释为时间时返回一个表示小时的整数。
hour (expression )
day
此函数用于根据标准数字解释当 expression 小数部分被解释为日期时返回一个表示某天的整数。
day (expression )
week
此函数用于返回根据 ISO 8601 表示周数的整数。周数根据标准数字解释通过表达式的日期解释进行计算。
week (timestamp [, first_week_day [, broken_weeks [, reference_day]]] )
month
此函数用于返回包含在环境变量 MonthNames 中定义的月份名称的对偶值和一个介于 1 至 12 的整数。月份根据标准数字解释通过表达式的日期解释进行计算。
month (expression )
year
此函数用于根据标准数字解释当 expression 被解释为日期时返回一个表示年份的整数。
year (expression )
weekyear
此函数用于返回根据 ISO 8601 周数所属的年份。星期数范围在 1 和大约 52 之间。
weekyear (expression )
weekday
此函数用于返回包含以下名称的对偶值: 在环境变量 DayNames 中定义的日期名称。 介于 0-6 之间的整数对应于一周 (0-6) 的标定天。
weekday (date )
Timestamp 函数
now
此函数用于返回系统时钟的当前时间的时间戳。默认值为 1。
now ([
timer_mode] )
today
此函数用于返回系统时钟的当前日期。
today ([timer_mode] )
LocalTime
此函数用于返回指定时区的系统时钟的当前时间戳。
localtime ([timezone [, ignoreDST ]] )
Make 函数
makedate
此函数用于返回根据年份 YYYY 、月份 MM 和日期 DD 计算的日期。
makedate (YYYY [ , MM [ , DD ] ] )
makeweekdate
此函数用于返回根据年份 YYYY 、星期 WW 和星期几 D 计算的日期。
makeweekdate (YYYY [ , WW [ , D ] ] )
maketime
此函数用于返回根据小时 hh 、分钟 mm 和秒 ss 计算的时间。
maketime (hh [ , mm [ , ss [ .fff ] ] ] )
其他日期函数
AddMonths
此函数用于返回在 startdate 后 n 个月内发生的日期,或者如果 n 为负数,则用于返回 startdate 前 n 个月内发生的日期。
addmonths (startdate , n
, [ , mode] )
AddYears
此函数用于返回在 startdate 后 n 年内发生的日期,或者如果 n 为负数,则用于返回 startdate 前 n 年内发生的日期。
addyears (startdate , n )
yeartodate
此函数用于判断输入日期是否在最后加载脚本的日期的年份以内,并返回 True (如果在)或返回 False (如果不在)。
yeartodate (timestamp [ , yearoffset
[ , firstmonth [ , todaydate] ] ] )
Timezone 函数
timezone
此函数根据 Windows 的定义返回当前时区的名称,不考虑日光节约时间调整。
timezone ( )
GMT
此函数返回来自系统时钟和 Windows 时间设置的日期和当前 Greenwich Mean Time 。
GMT ( )
UTC
返回日期和当前 Coordinated Universal Time 。
UTC ( )
converttolocaltime
将 UTC 或 GMT 时间戳转换为本地时间作为对偶值。此地方可为全世界任何一个城市和时区。
converttolocaltime (timestamp [, place [, ignore_dst=false]] )
设置时间函数
setdateyear
该函数获取 timestamp 和 year 的输入,并使用输入中指定的 year 更新 timestamp 。
setdateyear
(timestamp, year )
setdateyearmonth
该函数获取 timestamp 、month 和 year 的输入,并使用输入中指定的 year 和 month 更新 timestamp 。
setdateyearmonth
(timestamp, year, month )
In... 函数
inyear
此函数用于返回 True ,如果 timestamp 位于包含 base_date 的年份以内。
inyear (date, basedate , shift [, first_month_of_year
= 1] )
inyeartodate
此函数用于返回 True ,如果 timestamp 位于包含 base_date 为止以及包括 base_date 最后毫秒的年份部分以内。
inyeartodate
(date, basedate , shift [, first_month_of_year
= 1] )
inquarter
此函数用于返回 True ,如果 timestamp 位于包含 base_date 的季度以内。
inquarter
(date, basedate , shift [, first_month_of_year
= 1] )
inquartertodate
此函数用于返回 True ,如果 timestamp 位于包含 base_date 为止以及包括 base_date 最后毫秒的季度部分以内。
inquartertodate
(date, basedate , shift [, first_month_of_year
= 1] )
inmonth
此函数用于返回 True ,如果 timestamp 位于包含 base_date 的月份以内。
inmonth (date, basedate , shift )
inmonthtodate
用于返回 True ,如果 timestamp 位于包含 base_date 为止以及包括 base_date 最后毫秒的月份部分以内。
inmonthtodate
(date, basedate , shift )
inmonths
此函数用于查找时间戳是否在作为基准日期的同一个月、两个月、季度、四个月或半年内。另外,它也可以用于判断时间戳是否位于上一个或下一个时间周期以内。
inmonths (n, date, basedate , shift [, first_month_of_year
= 1] )
inmonthstodate
此函数用于判断时间戳是否位于截止以及包括 base_date 的最后毫秒的某个月、两个月、季度、四个月或半年周期的一部分以内。另外,它也可以用于判断时间戳是否位于上一个或下一个时间周期以内。
inmonthstodate
(n, date, basedate , shift [, first_month_of_year
= 1] )
inweek
此函数用于返回 True ,如果 timestamp 位于包含 base_date 的星期以内。
inweek (date, basedate , shift [, weekstart] )
inweektodate
此函数用于返回 True ,如果 timestamp 位于包含 base_date 为止以及包括 base_date 最后毫秒的星期部分以内。
inweektodate
(date, basedate , shift [, weekstart] )
inlunarweek
如果 timestamp 位于包含 base_date 的阴历周之内,则此函数返回 True。QlikView 中的阴历周将 1 月 1 日定义为一周的第一天。
inlunarweek
(date, basedate , shift [, weekstart] )
inlunarweektodate
如果 timestamp 位于截止且包括 base_date 最后毫秒的阴历周的某部分之内,则此函数返回 True。QlikView 中的阴历周将 1 月 1 日定义为一周的第一天。
inlunarweektodate
(date, basedate , shift [, weekstart] )
inday
此函数用于返回 True ,如果 timestamp 位于包含 base_timestamp 的一天以内。
inday (timestamp, basetimestamp , shift [, daystart] )
indaytotime
此函数用于返回 True ,如果 timestamp 位于包含 base_timestamp 为止以及包括 base_timestamp 精确毫秒的日子部分以内。
indaytotime (timestamp, basetimestamp , shift [, daystart] )
Start ... end 函数
yearstart
此函数用于返回与包含 date 的年份的第一天的开始对应的时间戳。默认的输出格式为在脚本中所设置的 DateFormat 。
yearstart ( date [, shift = 0 [, first_month_of_year
= 1]] )
yearend
此函数用于返回与包含 date 的年份的最后一天的最后毫秒时间戳对应的值。默认的输出格式为在脚本中所设置的 DateFormat 。
yearend ( date [, shift = 0 [, first_month_of_year
= 1]] )
yearname
此函数用于返回一个四位数年份的显示值,带有与包含 date 的年份的第一天的第一毫秒时间戳对应的基本数值。
yearname (date [, shift = 0 [, first_month_of_year
= 1] ] )
quarterstart
此函数用于返回与包含 date 的季度的第一毫秒的时间戳对应的值。默认的输出格式为在脚本中所设置的 DateFormat 。
quarterstart (date [, shift = 0 [, first_month_of_year
= 1]] )
quarterend
此函数用于返回与包含 date 的季度的最后毫秒的时间戳对应的值。默认的输出格式为在脚本中所设置的 DateFormat 。
quarterend (date [, shift = 0 [, first_month_of_year
= 1]] )
quartername
此函数用于返回一个显示值,该值显示季度的月(根据 MonthNames 脚本变量的格式)以及年,伴随一个与该季度第一天第一毫秒的时间戳对应的基础数值。
quartername (date [, shift = 0 [, first_month_of_year = 1]] )
monthstart
此函数用于返回与包含 date 的月份的第一天的第一毫秒时间戳对应的值。默认的输出格式为在脚本中所设置的 DateFormat 。
monthstart (date [, shift = 0] )
monthend
此函数用于返回与包含 date 的月份的最后一天的最后毫秒时间戳对应的值。默认的输出格式为在脚本中所设置的 DateFormat 。
monthend (date [, shift = 0] )
monthname
此函数用于返回一个显示值,该值显示该月(根据 MonthNames 脚本变量的格式)以及年,伴随一个与该月第一天第一毫秒的时间戳对应的基础数值。
monthname (date [, shift = 0] )
monthsstart
此函数用于返回与包含基准日期的一个月、两个月、季度、四个月或半年的第一毫秒的时间戳对应的值。另外,它也可以用于判断上一个或下一个时间周期的时间戳。
monthsstart (n, date [, shift = 0 [, first_month_of_year
= 1]] )
monthsend
此函数用于返回与包含基准日期的一个月、两个月、季度、四个月或半年的最后毫秒的时间戳对应的值。另外,它也可以用于判断上一个或下一个时间周期的时间戳。
monthsend (n, date [, shift = 0 [, first_month_of_year
= 1]] )
monthsname
此函数用于返回一个显示值,表示时段各月份(根据 MonthNames 脚本变量的格式)和年的范围。基础数值与包含基准日期的一个月、两个月、季度、四个月或半年的第一毫秒的时间戳对应。
monthsname (n, date [, shift = 0 [, first_month_of_year = 1]] )
weekstart
此函数用于返回与包含 date 的日历周的第一天(周一)的第一毫秒时间戳对应的值。默认输出格式是在脚本中设置的 DateFormat 。
weekstart (date [, shift = 0 [,weekoffset = 0]] )
weekend
此函数用于返回与包含 date 的日历周的最后一天(周日)的最后一毫秒时间戳对应的值。默认的输出格式为在脚本中所设置的 DateFormat 。
weekend (date [, shift = 0 [,weekoffset = 0]] )
weekname
此函数用于返回一个值,显示带有与包含 date 的周的第一天的第一毫秒时间戳对应的基本数值对应的年份和周数。
weekname (date [, shift = 0 [,weekoffset = 0]] )
lunarweekstart
此函数用于返回与包含 date 的阴历周的第一毫秒的时间戳对应的值。QlikView 中的阴历周将 1 月 1 日定义为一周的第一天。
lunarweekstart (date [, shift = 0 [,weekoffset = 0]] )
lunarweekend
此函数用于返回与包含 date 的阴历周的最后毫秒的时间戳对应的值。QlikView 中的阴历周将 1 月 1 日定义为一周的第一天。
lunarweekend (date [, shift = 0 [,weekoffset = 0]] )
lunarweekname
此函数用于返回一个显示值,显示与包含 date 的阴历周的第一天的第一毫秒时间戳对应的年份和阴历周数。QlikView 中的阴历周将 1 月 1 日定义为一周的第一天。
lunarweekname (date [, shift = 0 [,weekoffset = 0]] )
daystart
此函数用于返回与 time 参数中包含的一天的最后毫秒时间戳对应的值。默认的输出格式为在脚本中所设置的 TimestampFormat 。
daystart (timestamp [, shift = 0 [, dayoffset = 0]] )
dayend
此函数用于返回与 time 中包含的一天的最后毫秒的时间戳对应的值。默认的输出格式为在脚本中所设置的 TimestampFormat 。
dayend (timestamp [, shift = 0 [, dayoffset = 0]] )
dayname 此函数用于返回一个值,显示与包含 time 当天第一毫秒的时间戳对应的基本数值的日期。
dayname (timestamp [, shift = 0 [, dayoffset = 0]] )
Day numbering 函数 age age 函数用于返回某人在 date_of_birth 出生的 timestamp (完整年份)时的年龄。
age (timestamp,
date_of_birth )
networkdays networkdays 函数用于返回工作日的编号(周一至周五),在 start_date 和 end_date 之间,并将任何列出的可选 holiday 考虑在内。
networkdays
(start:date, end_date {, holiday} )
firstworkdate firstworkdate 函数用于返回最近的起始日以获得 no_of_workdays (周一至周五),它不迟于 end_date ,并已将任何列出的可选节假日考虑在内。end_date 和 holiday 应是有效的日期或时间戳。
firstworkdate (end_date, no_of_workdays {, holiday } )
lastworkdate lastworkdate 函数用于返回最早的结束日以获得 no_of_workdays (周一至周五),如果在 start_date 开始考虑任何列出的可选 holiday 。start_date 和 holiday 应是有效的日期或时间戳。
lastworkdate (start_date, no_of_workdays {, holiday} )
daynumberofyear 此函数用于计算时间戳所属的年份的天数。从该年度的第一天的第一毫秒开始计算,但可以偏移第一个月。
daynumberofyear (date[,firstmonth] )