سؤال

I have a csv file with four columns that contain a date.

StartDate, EndDate, ActionDate, MaturityDate 18/01/2013, 18-01-2013, 18-01-2013 07:59 PM, 18-01-2013 19:59

I am loading this into a table with:

myTable:("DDDD";enlist ",") 0: `$":/home/myuser/test.csv"

my table headers are OK, but the dates come in blank. I assume that is because Q only understands yyyy.mm.dd Unfortunately I have no control of the format of the csv files. I could re-format it with a python script before loading it into kdb, but is that the best way? Can I do that somehow in Q and make it understand these strings as dates?

Thanks

هل كانت مفيدة؟

المحلول

As you eluded to in your comments, the issue isn't that q can't parse dates delimited by "/", the issue is that the dates are in the format of date/month, rather than month/date. When using the correct date format (\z 0) will work for 3 of your columns above, although it will fall down with non-24hr clock times (.i.e AM/PM).

If each column is consistent, as in will always be month/date or date/month, then you could add some logic to parse correctly by temporarily setting \z. You would need to know ahead of time the format of the date column and parse accordingly. You could add logic to try to figure out the format of the date column, but there's a good chance that will hit some issues.

For AM/PM times, you could remove the postfix. If you actually want the date time you can use "Z" to parse instead and add 12:00:00 when the time is PM.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top