setdateyearmonth - 指令碼與圖表函數
此函數會輸入 timestamp 、month 與 year ,並使用輸入中指定的 year 和 month 更新 timestamp 。 .
語法:
SetDateYearMonth
( timestamp, year, month )
傳回的資料類型: 雙值
引數:
引數
timestamp
標準 Qlik Sense 時間戳記 (通常只是日期)。
year
四位數的年度。
month
1 位數或 2 位數的月份。
範例與結果:
這些範例使用日期格式 DD/MM/YYYY 。日期格式是在位於資料載入指令碼頂端的 SET DateFormat 陳述式中指定。變更範例中的格式,以滿足您的需求。
指令碼處理範例
setdateyearmonth ('29/10/2005', 2013, 3)
傳回 '29/03/2013
setdateyearmonth ('29/10/2005 04:26:14',
2013, 3)
傳回 '29/03/2013 04:26:14 ' 若要查看視覺化中時間戳記的時間部分,您必須將數字格式設定為「日期」,並從顯示時間值的「格式設定」中選取一個值。
範例:
將範例指令碼新增至您的應用程式並予以執行。若要查看結果,將結果資料行中列出的欄位新增至您應用程式中的工作表。
SetYearMonth:
Load *,
SetDateYearMonth(testdates, 2013,3) as NewYearMonth
Inline [
testdates
1/11/2012
10/12/2012
2/1/2013
19/5/2013
15/9/2013
11/12/2013
14/5/2014
13/6/2014
7/7/2014
4/8/2014
];
產生的表格包含原始日期及資料行,其中年已設為 2013。
結果表格 testdates NewYearMonth 1/11/2012 1/3/2013 10/12/2012 10/3/2013 2/1/2012 2/3/2013 19/5/2013 19/3/2013 15/9/2013 15/3/2013 11/12/2013 11/3/2013 14/5/2014 14/3/2013 13/6/2014 13/3/2013 7/7/2014 7/3/2013 4/8/2014 4/3/2013