Navigation
Connect

## How do I convert from symbol to integer?

Convert to string, then to int by applying the \$ (cast) operator while passing an uppercase type character as its left argument:

q)"I" \$ string `123
123
q)

Type number also works:

q)type 123
-6h
q)-6h \$ string `123
123
q)

See also: string to symbol conversion faq, Datatypes and \$

## How do I cast a string to a symbol?

By applying the \$ (cast) operator while passing ` (the null symbol) as its left argument:

q)` \$ "foo"
`foo
q)

The cast operator also accepts an uppercase type character as its left argument:

q)"S" \$ "foo"
`foo
q)

Moreover, you can convert a list of strings at once:

q)"S" \$ ("foo"; "bar"; "baz")
`foo`bar`baz
q)

To go the other way, use the string function:

q)string `foo
"foo"
q)

Since the string function is implemented as the monadic form (i.e., single argument overload) of the k function \$

q)string
\$:
q)

— it is also possible to write the above cast as follows:

q)(\$)`foo
"foo"
q)

Although we don't recommend it, we thought you should know in case you see it in the wild.

See also: type

## How do I extract the milliseconds from a time?

mod 1000:

q)now: .z.T
q)now
00:15:00.812
q)now mod 1000
00:00:00.812

If you want the milliseconds as an integer, you can simply follow the mod with a conversion to int:

q)`int\$ now mod 1000
812

You don't want to pass a datetime to mod; the result you'll get is not what you had in mind. You must convert it to a time first:

q)now: .z.Z
q)now
2011.03.26T09:51:26.624
q)now mod 1000
102.4107
q)`int\$ (`time\$ now) mod 1000
624
q)