kevbuntu
kevbuntu

Reputation: 501

how to cast a timestamp into a date format in kdb

I am trying to cast a column of a timestamp into date format

eventTimestamp

2016.11.02D04:25:01.599000000

Into:

eventTimestamp

2016.11.02

using update"D"$column from table

does not work. I guess I need to parse it out of the string first!

Upvotes: 1

Views: 4329

Answers (1)

Cmccarthy1
Cmccarthy1

Reputation: 388

The use of upper case letters for casting is used on string inputs as you say the cast you're looking for is as follows

q)show tab:([]100?0p;100?0t)
q)tab
x                             x1          
------------------------------------------
2001.03.18D08:40:47.804237904 21:10:45.900
2001.10.11D22:11:37.961901872 20:23:25.800
2001.10.06D22:58:22.399235216 19:03:52.074
2002.11.27D20:28:07.114942080 00:29:38.945
2003.12.31D10:15:38.085363056 04:30:47.898

// Cast the timestamp column to date
q)update `date$x from tab
x          x1          
-----------------------
2001.03.18 21:10:45.900
2001.10.11 20:23:25.800
2001.10.06 19:03:52.074
2002.11.27 00:29:38.945
2003.12.31 04:30:47.898

Upvotes: 4

Related Questions