All Apps and Add-ons

Duration calculation going wrong

wimvdheijkant
New Member

Dear all,

I'm trying to calculate duration. But what I get returned is off by 2 hours...? I'm using the following:
Search | convert timeformat="%d-%m-%Y %H:%M:%S" mktime(ADCreatedTime) |
convert timeformat="%d-%m-%Y %H:%M:%S" mktime(FIMCreatedTime) |
where ADCreatedTime > FIMCreatedTime |
Eval Duration = ADCreatedTime - FIMCreatedTime |

convert timeformat="%H:%M:%S" ctime(Duration) as D |
convert timeformat="%d-%m-%Y %H:%M:%S" ctime(ADCreatedTime) as ADC |
convert timeformat="%d-%m-%Y %H:%M:%S" ctime(FIMCreatedTime) as FDC |
Table user, FDC, ADC, D

The results are: user FDC ADC D
abiggelaar 25-03-2011 11:02:34 25-03-2011 12:05:49 03:03:15
ahayward 16-02-2011 12:54:59 16-02-2011 13:57:49 03:02:50
beheer.danaher 04-03-2011 09:49:39 04-03-2011 10:53:39 03:04:00

I can't find any time zone stuff going wrong. Can anyone point me in the right direction? Thanks! Wim

0 Karma
1 Solution

alacercogitatus
SplunkTrust
SplunkTrust

The convert that you are doing on Duration converts the duration into a time based on the epoch. So its saying that Duration is 3 hours 3 minutes 15 seconds from the epoch (for abiggelaar). You want to use an eval tostring evaluation. Replace convert timeformat="%H:%M:%S" ctime(Duration) as D with eval D=tostring(Duration,"duration") and it should give you what you want.

http://docs.splunk.com/Documentation/Splunk/5.0/SearchReference/CommonEvalFunctions

View solution in original post

wimvdheijkant
New Member

Problem solved, thanks!

0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

The convert that you are doing on Duration converts the duration into a time based on the epoch. So its saying that Duration is 3 hours 3 minutes 15 seconds from the epoch (for abiggelaar). You want to use an eval tostring evaluation. Replace convert timeformat="%H:%M:%S" ctime(Duration) as D with eval D=tostring(Duration,"duration") and it should give you what you want.

http://docs.splunk.com/Documentation/Splunk/5.0/SearchReference/CommonEvalFunctions

Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...