# 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:** 1\
**Showing post:** 2

<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";
}
```

---

_[View the full topic](https://discuss.elastic.co/t/set-relative-time-with-timestamp/177152)._
