read csv file - convert string to datetime

648 views
Skip to first unread message

Ivan

unread,
Apr 12, 2013, 8:12:27 AM4/12/13
to personal...@googlegroups.com
Hi all!
 
In my csv file date is stored as 20130315185540686 (meaning 2013.03.15T18:55:40.686).
 
Is there a possibility to convert that string into datetime "on the run" during the reading process? Or perhaps split it into two separate date and time columns?
 
I am using following string to read csv file:
.Q.fs[{`:tst/orderlog/ upsert .Q.en[`:tst] flip `symbol`sys`typ`moment`id`action`price`volume`id_deal`price_deal`own`account!("SCCJJIFIJFIS";",")0:x}]`:3.csv
 
 
Thank you.

Charles Skelton

unread,
Apr 12, 2013, 8:28:19 AM4/12/13
to personal...@googlegroups.com
update date:"D"$8#'date,time:"T"$-9#'date from ([]date:10#enlist "20130315185540686")
so embed it like

.Q.fs[{`:tst/orderlog/ upsert .Q.en[`:tst] update "D"$8#'date,time:"T"$-9#'date from flip`symbol`sys`typ`moment`id`action`price`volume`id_deal`price_deal`own`account!("SCCJJIFIJFIS";",")0:x}]`:3.csv

I dont know which of your col names
`symbol`sys`typ`moment`id`action`price`volume`id_deal`price_deal`own`account
refers to date[time] though... so I just called it date; change it as necessary.



--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbpl...@googlegroups.com.
To post to this group, send email to personal...@googlegroups.com.
Visit this group at http://groups.google.com/group/personal-kdbplus?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Charles Skelton

unread,
Apr 12, 2013, 8:38:49 AM4/12/13
to personal...@googlegroups.com
btw, for this use type id "*" to read the date[time] column from the csv

Ivan

unread,
Apr 12, 2013, 8:57:39 AM4/12/13
to personal...@googlegroups.com
Thank you,
 
seems I can make it work after some effort

WooiKent Lee

unread,
Apr 12, 2013, 9:18:28 AM4/12/13
to personal...@googlegroups.com
Or you can do:
update "Z"$((8#'date),'"T",/:(-9#'date)) from ([]date:10#enlist "20130315185540686")
 
.Q.fs[{`:tst/orderlog/ upsert .Q.en[`:tst] update "Z"$((8#'date),'"T",/:(-9#'date)) from flip`symbol`sys`typ`moment`id`action`price`volume`id_deal`price_deal`own`account!("SCCJJIFIJFIS";",")0:x}]`:3.csv
Message has been deleted

Ivan

unread,
Apr 12, 2013, 9:32:11 AM4/12/13
to personal...@googlegroups.com
I have made it almost same
 

update ("D"$8#'moment)+("T"$-9#'moment)

Is it a good approach?

Attila Vrabecz

unread,
Apr 12, 2013, 9:43:23 AM4/12/13
to personal...@googlegroups.com
update sum("DT";8 9)0:date from 
is a bit faster (no each)  and shorter

Cheers,
  Attila

WooiKent Lee

unread,
Apr 12, 2013, 11:20:33 AM4/12/13
to personal...@googlegroups.com
I think this is fine, as long as the type of the result is what you need (well you result will end up to be time stamp type)...
 
But you can easily recast it anyway... So you're good!! :)
Reply all
Reply to author
Forward
0 new messages