Kdbplus-q-language-temporal-data
提供:Dev Guides
Q言語-時間データ
*q* 言語には、時刻や日付などの時間データを表現および操作するさまざまな方法があります。
Date
基準日は01Jan2000なので、kdb +の日付は整数の日数として内部的に保存されます。 この日付の後の日付は内部的に正の数として保存され、それより前の日付は負の数として参照されます。
デフォルトでは、日付は「YYYY.MM.DD」の形式で書き込まれます
q)x:2015.01.22 /This is how we write 22nd Jan 2015
q)`int$x /Number of days since 2000.01.01
5500i
q)`year$x /Extracting year from the date
2015i
q)x.year /Another way of extracting year
2015i
q)`mm$x /Extracting month from the date
1i
q)x.mm /Another way of extracting month
1i
q)`dd$x /Extracting day from the date
22i
q)x.dd /Another way of extracting day
22i
- 算術および論理演算*は、日付に直接実行できます。
q)x+1 /Add one day
2015.01.23
q)x-7 /Subtract 7 days
2015.01.15
2000年1月1日は土曜日に落ちました。 したがって、履歴全体または将来の土曜日を7で割ると、残りは0、日曜日は1、月曜日は2になります。
Day mod 7
Saturday 0
Sunday 1
Monday 2
Tuesday 3
Wednesday 4
Thursday 5
Friday 6
タイムズ
時間は、午前0時のストロークからのミリ秒の整数として内部的に保存されます。 時間はHH:MM:SS.MSSの形式で記述されます
q)tt1: 03:30:00.000 /tt1 store the time 03:30 AM
q)tt1
03:30:00.000
q)`int$tt1 /Number of milliseconds in 3.5 hours
12600000i
q)`hh$tt1 /Extract the hour component from time
3i
q)tt1.hh
3i
q)`mm$tt1 /Extract the minute component from time
30i
q)tt1.mm
30i
q)`ss$tt1 /Extract the second component from time
0i
q)tt1.ss
0i
日付の場合のように、算術は時間に直接実行できます。
日時
日時は、ISO標準形式のように「T」で区切られた日付と時刻の組み合わせです。 日時値には、2000年1月1日午前0時からの小数日数が格納されます。
q)dt:2012.12.20T04:54:59:000 /04:54.59 AM on 20thDec2012
q)type dt
-15h
q)dt
2012.12.20T04:54:59.000
9
q)`float$dt
4737.205
基になる端数の日数は、フロートにキャストすることで取得できます。