BlackPearl
BlackPearl

Reputation: 115

kdb+ Date format getting changed when saving to csv

Please find below sample trade table.

kdb+ trades table sample:
q)5#trades

date       symbol price
------------------------
2019.11.23 abc    107.88
2019.11.07 xyz    103.19
2019.11.02 pqr    101.52
2019.11.25 abc    101.26
2019.11.06 abc    100.34

q)

When I save the trade table to csv, the date format is getting changed from "YYYY.MM.DD" to "YYYY-MM-DD".

csv file sample:

date,symbol,price
2019-11-23,abc,107.88
2019-11-07,xyz,103.19
2019-11-02,pqr,101.52
2019-11-25,abc,101.26
2019-11-06,abc,100.34

To save the trades table I had used "save `:trades.csv". I even tried to cast date to string before saving but that also didnt help. Can someone please take a look here and advise further?

Thanks in advance! Haider

Upvotes: 1

Views: 432

Answers (1)

Michael McParland
Michael McParland

Reputation: 906

I think the below is what you are after. Looks like the standard way defaults to "YYYY-MM-DD" so updating the date column to string first gets around this.

trades:([]date:2019.11.23 2019.11.07;symbol:`abc`xyz;price:107.88 103.19)
q)update string date from `trades
`trades
q)save `:trades.csv
`:trades.csv
q)\cat trades.csv
"date,symbol,price"
"2019.11.23,abc,107.88"
"2019.11.07,xyz,103.19"

Upvotes: 3

Related Questions