# Set relative time with timestamp

**URL:** <https://discuss.elastic.co/t/set-relative-time-with-timestamp/177152>\
**Category:** Kibana\
**Created:** [April 16, 2019, 8:33pm UTC](https://discuss.elastic.co/t/set-relative-time-with-timestamp/177152 "2019-04-16T20:33:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierre-Olivier\_Lerou](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pierre-olivier_lerou/32/44285_2.png) [@Pierre-Olivier\_Lerou](https://discuss.elastic.co/u/Pierre-Olivier_Lerou)\
**Post date:** [April 16, 2019, 8:33pm UTC](https://discuss.elastic.co/t/set-relative-time-with-timestamp/177152/1 "2019-04-16T20:33:40Z")

</div>

Is there a way to show the timestamp as a relative time to now?

So I'm currently monitoring some services and I'm only showing the latest data for each service. I'm currently displaying the timestamp in this format: April 16th 2019, 16:31:47.375.  
I want to display it like: 60seconds ago or 2minutes ago. Is there a date format in Kibana that would let me do that. So [NOW-timestamp].

---

<div class="post-metadata">

**Author:** ![Pierre-Olivier\_Lerou](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pierre-olivier_lerou/32/44285_2.png) [@Pierre-Olivier\_Lerou](https://discuss.elastic.co/u/Pierre-Olivier_Lerou)\
**Post date:** [April 16, 2019, 9:45pm UTC](https://discuss.elastic.co/t/set-relative-time-with-timestamp/177152/2 "2019-04-16T21:45:12Z")

</div>

I was able to solve the problem once I knew that Scripted Fields existed so this is what I used to show how long ago the update was :

```
if(Math.round((new Date().getTime()-doc['@timestamp'].value)/1000)>7200){
   return Math.round((new Date().getTime()-doc['@timestamp'].value)/3600000) + " hours ago";
}else if(Math.round((new Date().getTime()-doc['@timestamp'].value)/1000)>3600){
   return Math.round((new Date().getTime()-doc['@timestamp'].value)/3600000) + " hour ago";
}else if(Math.round((new Date().getTime()-doc['@timestamp'].value)/1000)>120){
   return Math.round((new Date().getTime()-doc['@timestamp'].value)/60000) + " minutes ago";
} else if(Math.round((new Date().getTime()-doc['@timestamp'].value)/1000)>60){
   return Math.round((new Date().getTime()-doc['@timestamp'].value)/60000) + " minute ago";
}else {
   return Math.round((new Date().getTime()-doc['@timestamp'].value)/1000) + " seconds ago";
}
```

---

<div class="post-metadata">

**Author:** ![rashmi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rashmi/32/16391_2.png) [@rashmi](https://discuss.elastic.co/u/rashmi)\
**Post date:** [April 17, 2019, 1:42pm UTC](https://discuss.elastic.co/t/set-relative-time-with-timestamp/177152/3 "2019-04-17T13:42:15Z")

</div>

Thanks for posting your solution.

Cheers  
Rashmi

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 15, 2019, 1:42pm UTC](https://discuss.elastic.co/t/set-relative-time-with-timestamp/177152/4 "2019-05-15T13:42:17Z")

</div>

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