Convert timestamp in Curl command?

Hi there,

I have an InfluxDB 2 which I query via curl in a script on the commandline, using the InfluxQL endpoint ($1 is the query):

curl --get “http://myserver/query” -H “precision: rfc3339” -H “Accept: application/csv” --header “Authorization: Token x” --data-urlencode “db=mydb” --data-urlencode "q=$1

Everything works fine, but I always get back time values as Unix timestamp - but I would like to have a readable output like “2024-01-01 12:00:00”. As far as I read, that should be the case with setting the precission? But it doesn’t work via the API?

The precision header in your request impacts how data is written, not how it’s read.
But you can use this function to return the rfc format:Operate on timestamps with Flux | InfluxDB Cloud (TSM) Documentation
You’d want to do that with a map function on the _time column :slight_smile:
Let me know if that helps!

Thanks, but that seems to be a Flux function, InfluxQL doesn’t know it, or am I doing something wrong in the query:

select name, time(v: _time) from W limit 10

Hello @TomZastrow,
yes that’s a flux function I assumed you were working with flux since you tagged influxdb v2 and flux is the query language for v2. What version are you using?
I don’t know if there’s a way to do that with the API for v1?

You can do that with the CLI:

Which by default returns rfc3339.

Thanks, your first example shows the time nicely formatted, but this seems not to work. I’ll do some scripting around the query :wink: