Return date as UTC+0


I have a field containing seconds which I wish to convert to HH:mm:ss format in my visualization; I'm performing this using a scripted field of type date. This works fine, however if I specify a value of xx my conversion comes back with 1:00:xx. I assume the additional hour is due to my location which is currently under BST (UTC+1). So my question is how do I get the script to always return the value as UTC+0.

My script currently contains:
doc['doc.stats.OPERATOR_ASSISTS_AVERAGE_ANSWER_TIME'].value * 1000

Many thanks in advance

(Matt Bargar) #2

Date fields must represent an exact point in time. They can't represent durations, which I think is what you're looking for. If you just want to display the number of seconds stored in stats.OPERATOR_ASSISTS_AVERAGE_ANSWER_TIME in a more human readable format, I would recommend using a field formatter.


Hello Matt,
thanks for the reply.

Indirectly the field does represent an exact point in time albeit from 1970; so my question is more related to how do I get around seasonal time adjustments in general. I have the same issue with other true date fields.

My queries now work because the UK has moved to GMT but my dashboards will go awry again next summer.

The elastic server is always running in GMT so I assume the time adjustments are being performed by my browser and this is the issue I wish to work around. I was hoping that a more advanced painless script would address this for me.

(Matt Bargar) #4

Kibana will do timezone conversion on date fields using your local tz by default. That's probably what is affecting your field. You can change this to a static timezone if you wish (see dateFormat:tz here).

However, I still don't understand why you would want to use a date type field for this use case. Am I correct in understanding that stats.OPERATOR_ASSISTS_AVERAGE_ANSWER_TIME contains the number of seconds that it took to do something (a duration)? And you want to convert this number of seconds into a more human readable format? If so I'd highly recommend checking out the "Duration" numeric field formatter. Sorry if I'm just misunderstanding what you're trying to do.


I tried the number field formatter with type Duration but the responses are far to vague, 12 seconds comes out as "a few seconds" or 1 minute 30 as "around a couple of minutes". If I could use the field as it is intended i.e. a duration specified in seconds I would do. So the only solution I can see is to pretend it is a date so I can format it into HH:mm:ss .


Changing the dateFormat:tx option to UTC has fixed my issue.

Many thanks Matt.

(system) #7

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.