DQL
Questions about Dynatrace Query Language
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get the differnce betweent two timestamp

marusla
Participant

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

3 REPLIES 3

JeanBlanc
Advisor

Hi @marusla 🙂

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:

 
| fieldsAdd Difference = DiffMs - DiffSec

So your full query would look like:

| 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,

i use the commands, but stil have the problem

 

marusla_0-1764020725469.png

 

Thanks, i have i have to use other convertion 

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

Featured Posts