# How to get the differnce betweent two timestamp

**URL:** <https://community.dynatrace.com/t/how-to-get-the-differnce-betweent-two-timestamp/54190>\
**Category:** DQL\
**Tags:** dql, logs\
**Created:** [November 24, 2025, 9:17pm UTC](https://community.dynatrace.com/t/how-to-get-the-differnce-betweent-two-timestamp/54190 "2025-11-24T21:17:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marusla](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marusla/32/24217_2.png) [@marusla](https://community.dynatrace.com/u/marusla)\
**Post date:** [November 24, 2025, 9:17pm UTC](https://community.dynatrace.com/t/how-to-get-the-differnce-betweent-two-timestamp/54190/1 "2025-11-24T21:17:13Z")

</div>

Hello i have this code

| fieldsAdd FechaTs = toTimestamp(Fecha)  
| summarize  
FechaInicial = min(FechaTs),  
FechaFinal = max(FechaTs),  
by: { Identificador }  
| fieldsAdd  
DiffMs = toLong(FechaFinal - FechaInicial),  
DiffSec = toLong((FechaFinal - FechaInicial) / 1000)  
| sort DiffMs desc

---

<div class="post-metadata">

**Author:** ![JeanBlanc](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/jeanblanc/32/25897_2.png) [@JeanBlanc](https://community.dynatrace.com/u/JeanBlanc)\
**Post date:** [November 24, 2025, 9:37pm UTC](https://community.dynatrace.com/t/how-to-get-the-differnce-betweent-two-timestamp/54190/2 "2025-11-24T21:37:03Z")

</div>

Hi&nbsp;[@marusla](https://community.dynatrace.com/user/86794)&nbsp;🙂

You can calculate the difference directly during the pipeline by adding a new field that performs the subtraction between the two values you already computed.

For example, after defining DiffMs and DiffSec, simply add:

```markup
| fieldsAdd Difference = DiffMs - DiffSec

```

So your full query would look like:

```markup
| fieldsAdd FechaTs = toTimestamp(Fecha) | summarize FechaInicial = min(FechaTs), FechaFinal = max(FechaTs), by: { Identificador } | fieldsAdd DiffMs = toLong(FechaFinal - FechaInicial), DiffSec = toLong((FechaFinal - FechaInicial) / 1000) | fieldsAdd Difference = DiffMs - DiffSec | sort DiffMs desc

```

This adds a new column with the subtraction result without modifying the rest of your logic.

Best regards,

---

<div class="post-metadata">

**Author:** ![marusla](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marusla/32/24217_2.png) [@marusla](https://community.dynatrace.com/u/marusla)\
**Post date:** [November 24, 2025, 9:45pm UTC](https://community.dynatrace.com/t/how-to-get-the-differnce-betweent-two-timestamp/54190/3 "2025-11-24T21:45:48Z")

</div>

i use the commands, but stil have the problem

![marusla_0-1764020725469.png](https://global.discourse-cdn.com/dynatrace/original/3X/3/e/3e1d24817060134d510e721992264e8dcfcb1d06.png)

---

<div class="post-metadata">

**Author:** ![marusla](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marusla/32/24217_2.png) [@marusla](https://community.dynatrace.com/u/marusla)\
**Post date:** [November 25, 2025, 1:42am UTC](https://community.dynatrace.com/t/how-to-get-the-differnce-betweent-two-timestamp/54190/4 "2025-11-25T01:42:33Z")

</div>

Thanks, i have i have to use other convertion

| summarize FechaInicial = min(Fecha), FechaFinal = max(Fecha), by: { Identificador}  
| fieldsAdd Duracion = (totimestamp(FechaFinal) - totimestamp(FechaInicial))
