# Calculate the TIMESTAMP duration

**URL:** <https://community.dynatrace.com/t/calculate-the-timestamp-duration/42082>\
**Category:** Logs\
**Tags:** dynatrace-managed, logs\
**Created:** [October 13, 2023, 3:42pm UTC](https://community.dynatrace.com/t/calculate-the-timestamp-duration/42082 "2023-10-13T15:42:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RPbiaggio](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@RPbiaggio](https://community.dynatrace.com/u/RPbiaggio)\
**Post date:** [October 13, 2023, 3:42pm UTC](https://community.dynatrace.com/t/calculate-the-timestamp-duration/42082/1 "2023-10-13T15:42:01Z")

</div>

Guys, I’m having great difficulty calculating the start and end times of my log. Does anyone know if this is really possible and if possible, give an example?

Log example:

 ![RPbiaggio_0-1697211685128.png](https://global.discourse-cdn.com/dynatrace/original/2X/2/2113e12598e02ab8b6dfe988251d70b5160dc657.png)

---

<div class="post-metadata">

**Author:** ![marina\_pollehn](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marina_pollehn/32/39120_2.png) [@marina\_pollehn](https://community.dynatrace.com/u/marina_pollehn)\
**Post date:** [October 17, 2023, 11:43am UTC](https://community.dynatrace.com/t/calculate-the-timestamp-duration/42082/2 "2023-10-17T11:43:25Z")

</div>

Hi&nbsp;[@RPbiaggio](https://community.dynatrace.com/user/67564)&nbsp;,

Do you mean calculating the difference between start and end time, so the duration?

Or do you have problems with finding the start and end time itself for dashboarding?

---

<div class="post-metadata">

**Author:** ![RPbiaggio](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@RPbiaggio](https://community.dynatrace.com/u/RPbiaggio)\
**Post date:** [October 17, 2023, 11:46am UTC](https://community.dynatrace.com/t/calculate-the-timestamp-duration/42082/3 "2023-10-17T11:46:05Z")

</div>

Sorry, yes, exactly, the duration.

---

<div class="post-metadata">

**Author:** ![radek\_jasinski](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/radek_jasinski/32/10432_2.png) [@radek\_jasinski](https://community.dynatrace.com/u/radek_jasinski)\
**Post date:** [October 17, 2023, 1:40pm UTC](https://community.dynatrace.com/t/calculate-the-timestamp-duration/42082/4 "2023-10-17T13:40:31Z")

</div>

Hi,

You need to know that: “All duration literals valid for the duration data type are applicable for the from: and to: parameters.”

See description of the use of DQL and examples for duration calculation here:

> **[DQL commands](https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/commands)**
>
> A list of DQL commands.

Radek

---

<div class="post-metadata">

**Author:** ![RPbiaggio](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@RPbiaggio](https://community.dynatrace.com/u/RPbiaggio)\
**Post date:** [October 17, 2023, 9:37pm UTC](https://community.dynatrace.com/t/calculate-the-timestamp-duration/42082/5 "2023-10-17T21:37:19Z")

</div>

Sorry, but I couldn’t understand this documentation and/or what I actually need to adjust here in the code. I currently have this configuration in the log rule.

USING(INOUT resource.run.createddate:TIMESTAMP, resource.run.finisheddate:TIMESTAMP)  
| FIELDS\_ADD(DurationTeste:(resource.run.createddate - resource.run.finisheddate))

I have the value in timestamp which is the difference between the creation and finish fields, but I am not able to convert this so that it shows me the data in minutes or hours.

 ![RPbiaggio_0-1697578616151.png](https://global.discourse-cdn.com/dynatrace/original/3X/1/c/1c5b0d0a773037ace671b725d4366fe95b84b225.png)

---

<div class="post-metadata">

**Author:** ![RPbiaggio](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@RPbiaggio](https://community.dynatrace.com/u/RPbiaggio)\
**Post date:** [December 4, 2023, 1:48pm UTC](https://community.dynatrace.com/t/calculate-the-timestamp-duration/42082/6 "2023-12-04T13:48:02Z")

</div>

Was made the follow code:

| FIELDS\_ADD(durationTimestamp:(TIMESTAMP(resource.job.finishtime) - TIMESTAMP(resource.job.starttime)))//  
| FIELDS\_ADD(segundos\_d:LONG(durationTimestamp)/1000000000000000)  
| FIELDS\_ADD(segundos\_d\_resto:MODULO(segundos\_d,60))  
| FIELDS\_ADD(minutos\_d:segundos\_d/60)  
| FIELDS\_ADD(horas\_d:minutos\_d/60)  
| FIELDS\_ADD(dias\_d:horas\_d/24)  
| FIELDS\_ADD(duracao\_total\_execucao\_job:horas\_d+“h:”+minutos\_d+“m:”+segundos\_d\_resto+“s”)  
| FIELDS\_ADD(Inicio:resource.job.starttime, Final:resource.job.finishtime)  
| FIELDS\_ADD(duracaototalpipeline:segundos\_d)
