# Convert Number into Time (HH:MM:SS)

**URL:** <https://discuss.elastic.co/t/convert-number-into-time-hhss/235494>\
**Category:** Kibana\
**Created:** [June 3, 2020, 8:17am UTC](https://discuss.elastic.co/t/convert-number-into-time-hhss/235494 "2020-06-03T08:17:17Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![angelo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/angelo/32/61325_2.png) [@angelo](https://discuss.elastic.co/u/angelo)\
**Post date:** [June 13, 2020, 2:46am UTC](https://discuss.elastic.co/t/convert-number-into-time-hhss/235494/4 "2020-06-13T02:46:35Z")

</div>

I'm not sure where this is going wrong. In my case, a 'duration' of 7200 always returns "02:00:00" given the format specified at the end for `my_answer`. This is regardless of asking Kibana to format it as a Number or String (with Number.js formatting of 00:00:00).

However, your last screenshot is a bit curious - if the `duration` value is 7200, you are showing a field of `duration_min`, which on its own would be equal to 120 minutes if you wanted to report it that way. If you do want it in HH:mm:ss format, then that should come out to 02:00:00 which is done via the string formatting of `my_answer`.

As a test, if you run the following in Kibana Dev Tools, do you get values of "02:00:00" and "01:05:00" using Nathan's example?

```auto
PUT test
{}
PUT test/_doc/1
{"elapsed_time": 7200}
PUT test/_doc/2
{"elapsed_time": 3900}
GET test/_search
{
  "script_fields": {
    "diff": {
      "script": """if (doc['elapsed_time'].size()==0) {
    return ""
} else {
    long elapsed_time=(long)doc["elapsed_time"].value;
    
    long minutesInseconds = 60;
    long hoursInseconds = minutesInseconds * 60;
    // long daysInMilli = hoursInMilli * 24;

    // long elapsedDays = elapsed_time / daysInMilli;
    // elapsed_time = elapsed_time % daysInMilli;
	
    long elapsedHours = elapsed_time / hoursInseconds;
    elapsed_time = elapsed_time % hoursInseconds;

    long elapsedMinutes = elapsed_time / minutesInseconds;
    elapsed_time = elapsed_time % minutesInseconds;
    
    long elapsedSeconds = elapsed_time;

    String my_answer = String.format("%02d:%02d:%02d", new def[] {(int)elapsedHours, (int)elapsedMinutes, (int)elapsedSeconds});
    return my_answer;
}"""
    }
  }
}

```

---

_[View the full topic](https://discuss.elastic.co/t/convert-number-into-time-hhss/235494)._
