Splunk Search

Average between 2 fields D+HH:MM:SS

Abarny
Path Finder

Hi,

I try to realize an average enter 2 fields which appear in the form of D+HH:MM:SS so i converted with dur2sec. But the result is 0 i don't understand why. Can you help me to find why ? Thanks you.

| convert dur2sec(AAAA)
| convert dur2sec(BBB)
|stats sum(AAA) as C sum(BBB) as D dc(E) as F
| eval temps=D-C | eval moyen= temps/F
| fields moyen

0 Karma
1 Solution

woodcock
Esteemed Legend

Try this:

| eval duration=strptime(BBB,"%Y-%m-%d %H:%M:%S") - strptime(AAA,"%Y-%m-%d %H:%M:%S")
|stats savg(duration) AS moyen

View solution in original post

0 Karma

woodcock
Esteemed Legend

Try this:

| eval duration=strptime(BBB,"%Y-%m-%d %H:%M:%S") - strptime(AAA,"%Y-%m-%d %H:%M:%S")
|stats savg(duration) AS moyen
0 Karma

richgalloway
SplunkTrust
SplunkTrust

What is field E? Counting a field that doesn't exist will make F=0

---
If this reply helps you, Karma would be appreciated.
0 Karma

Abarny
Path Finder

This field exist, E is an unique identifier on 1 event

0 Karma

niketn
Legend

Have you validated BBB and AAAA values are different or not?
Can you add few data samples?

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

Abarny
Path Finder

Yes they are différents exemple : AAA = 2017-02-18 11:53:05
BBB = 2017-02-18 11:53:14

But no i can't add data sample ..

0 Karma

somesoni2
Revered Legend

You said that your field values are in format D+HH:MM:SS (string formatted duration) but the sample values above shows that they are timestmap, which one is it? If it's timestamp then your convert dur2sec will fail and return 0/null. If they are timestamp, then give this a try

...your base search
| eval duration=strptime(BBB,"%Y-%m-%d %H:%M:%S")-strptime(AAA,"%Y-%m-%d %H:%M:%S")
|stats sum(duration) as duration dc(E) as F
| eval moyen= duration/F
| fields moyen

Abarny
Path Finder

Okay ! Thanks for your help !

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

SOK it to Me: Top 3 Benefits of Using Splunk Operator on Kubernetes that’ll Make ...

    Thursday, July 9, 2026  |  11:00AM–12:00PM PDT Duration: 1 hour (includes Q&A) Managing can feel like a ...

Upgrade Prep for 10.4, Network Observability Deep Dives, and More from Splunk Lantern

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

Splunk Developer Day announcements: AI agents, MCP tools, Forecasting, and Custom ...

Splunk Developer Day was packed with product and platform updates for developers building in the AI ...