KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ 0D infront of timespan

  • 0D infront of timespan

    Posted by ekallivrousis on January 11, 2022 at 12:00 am

    Im using .z.n in my tick.q and wondering if theres a way to not show 0D infront of the timespan.

    Currently it shows:

    0D20:06:22.271520000

    I want this

    20:06:22.271520000

     

    ekallivrousis replied 9 months, 1 week ago 4 Members · 4 Replies
  • 4 Replies
  • m_klontzakis

    Member
    January 11, 2022 at 12:00 am

    You can resolve this by casting the type from timespan to time.

    “t”$.z.n

    However, the result will be in milliseconds, not nanoseconds.

  • ekallivrousis

    Member
    January 11, 2022 at 12:00 am

    Yes but is it possible to keep as a timespan?

  • Laura

    Administrator
    January 13, 2022 at 12:00 am

    Hi

    If you want to keep the nanosecond granularity, you will have to keep the value as a timespan, and the prefacing 0D.

    You can see some more examples of time conversions here: https://code.kx.com/q/kb/temporal-data/#comparing-temporals

    Hope that helps clarify, and thanks for your questions!

    Laura

  • rocuinneagain

    Member
    January 13, 2022 at 12:00 am

    The day part is an integral portion of the datatype and will display by default.

     

    In a UI/display time it can be dropped if required:

    q)2_string .z.n /Atom "14:41:40.125906000" 
    q)2_/:string 2#.z.n /List "14:42:00.701751000" "14:42:00.701751000" 
    q)update 2_/:string time from ([] time:2#.z.n) 
    /Column in table 
    time 
    -------------------- 
    "14:42:38.625329000" 
    "14:42:38.625329000" 
    // All columns of timespan type in a table 
    q)dropDays:{c:where -16h=type each first x;$[count c;![x;();0b;c!{((/:;_);2;($:;x))}each c];x]} 
    q)dropDays ([] time:2#.z.n;b:1.1 1.2) 
    time b 
    ------------------------ 
    "14:47:37.376270000" 1.1 
    "14:47:37.376270000" 1.2

     

Log in to reply.