jqformatdatetime

Formatting ISO8601 date/time into number field


I am trying to use the following to format my data from date/time to a number field however it is passing me an error

Field "test": (.int.example_t | formatdate iso8601 | tonumber)

Error jq: error: syntax error, unexpected IDENT (Unix shell quoting issues?) at , line 13: "test": (.int.example_t | formatdate iso8601 | tonumber) jq: 1 compile error

Any idea any other ways to change the formatting?

So far I've only tried using

Field "test": (.int.example_t | formatdate iso8601 | tonumber)


Solution

  • You can instead formatdate (is not a built-in jq function) use the UNIX timestamp:

    jq '{ "test": (.int.example_t | todate // 0 | tonumber) }' input.json
    

    todate function converts the date/time string to a UNIX timestamp.