Search code examples
kdb

KDB - reformatting date


I'm formatting dates between day format YYYY.MM.DD and Monthly YYYY.MM and having some issues recasting data back and forth. Per Shock and Awe, I understand that the YYYY.MM format needs to be an integer however I'm having issues casting it correctly. Presently, I'm casting as a string to truncate the text and assign railing type indicator "m" but it returns an empty field.

I also have been looking at the Library as well .qdate.q_ but there doesn't seem to be a format for this.

I've read Shock and Awe here which makes complete sense Basic Data Types – Atoms

id   seg         scen      prod SegmentStartDate iMonthCount fcast    StartDate
-----------------------------------------------------------------------------------
AAA       1       PLAN      XXX     2014.08.01       1           238.3821 2014.08m
AAA       1       PLAN      XXX     2014.08.01       1           235.1754 2014.08m
AAA       1       PLAN      XXX     2014.08.01       1           232.0119 2014.08m
...

tblMonthly: update StartDate: `$((-3_'string SegmentStartDate),'("m")) from tblMonthly; //formats as sym 
tblMonthly: update StartDate: "I"$'string StartDate from tblMonthly; //fails to recast

Thanks in advance


Solution

  • You can cast directly to months like so:

    tblMonthly: update StartDate:"m"$SegmentStartDate from tblMonthly