# cast symbol to datetime

**URL:** <https://forum.kx.com/t/cast-symbol-to-datetime/9384>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [January 14, 2015, 8:10pm UTC](https://forum.kx.com/t/cast-symbol-to-datetime/9384 "2015-01-14T20:10:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhoonjhar](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@jhoonjhar](https://forum.kx.com/u/jhoonjhar)\
**Post date:** [January 14, 2015, 8:10pm UTC](https://forum.kx.com/t/cast-symbol-to-datetime/9384/1 "2015-01-14T20:10:00Z")

</div>

i am trying to load a CSV file into my tables where one of field is datetime in table and in CSV is string containing like “Jan 13 2015 8:18AM” values i have tried using $ cast. but did not get any value.&nbsp;

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [January 14, 2015, 9:22pm UTC](https://forum.kx.com/t/cast-symbol-to-datetime/9384/2 "2015-01-14T21:22:00Z")

</div>

based on a prior suggestion from Attila

q){sum[x[0 1;]]+?[x[2;]=`AM;00:00;12:00]}(“ZTS”;11 5 2)0:(“Jan 13 2015 8:18AM”;“Jan 12 2015 8:18PM”;“Jan 15 2015 8:24PM”)

2015.01.13T08:18:00.000 2015.01.12T20:18:00.000 2015.01.15T20:24:00.000

http://code.kx.com/wiki/Reference/ZeroColon

---

<div class="post-metadata">

**Author:** ![felix1](https://avatars.discourse-cdn.com/v4/letter/f/3e96dc/32.png) [@felix1](https://forum.kx.com/u/felix1)\
**Post date:** [January 14, 2015, 10:15pm UTC](https://forum.kx.com/t/cast-symbol-to-datetime/9384/3 "2015-01-14T22:15:00Z")

</div>

not always:

q){sum[x[0 1;]]+?[x[2;]=`AM;00:00;12:00]}(“ZTS”;11 5 2)0:(“Jan 13 2015 8:18AM”;“Jan 12 2015 8:18PM”;“Jan 15 2015 11:24PM”)

?length

---

<div class="post-metadata">

**Author:** ![Attila](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Attila](https://forum.kx.com/u/Attila)\
**Post date:** [January 15, 2015, 1:10am UTC](https://forum.kx.com/t/cast-symbol-to-datetime/9384/4 "2015-01-15T01:10:00Z")

</div>

not having leading zeroes is an insult on mankind

however that can be remedied (much slower than 0: of course)

p:DTS"$'flip(11#;-2\_11\_;-2#)@:/:

one also be have to be careful with midnight 0am/12am&nbsp;

a: {(x[0]+x[1]mod`int$12t)+12u*`PM=x 2}

q)a p (“Jan 13 2015 8:18AM”;“Jan 13 2015 0:18AM”;“Jan 13 2015 12:18AM”;“Jan 13 2015 8:18PM”)

2015.01.13D08:18:00.000000000 2015.01.13D00:18:00.000000000 2015.01.13D00:18:00.000000000 2015.01.13D20:18:00.000000000

Cheers,

&nbsp; Attila

>
