Getting Data In

Difference between the 2 time fields

Real_captain
Path Finder

Hi 

Can someone please let me know how i can find the difference between the 2 fields Start-Time and End-Time in the below search. 

Format of time extracted by the query is : 

Start-Time = 2024-01-23T11:38:59.0000000Z

End-Time = 2024-01-23T11:39:03.0000000Z

Query : 

`macro_events_prod_srt_shareholders_esa` eocEnv = PRO * "MICROSOFT.DATAFACTORY" activityName = Merge_Disclosure_Request 741b5db8-da47-468b-b883-a06ef137519a
| eval Dreqid=case('category'="PipelineRuns",'properties.Parameters.DisclosureRequestId','category'="ActivityRuns",'properties.Input.storedProcedureParameters.DisclosureRequestId.value',1=1,"")
| eval end_time=case('end'="1601-01-01T00:00:00.0000000Z", "Still-Running",1=1,'end')
| table eocEnv , start , end_time , pipelineName , activityName, pipelineRunId,level , status , category , Type , Dreqid, properties.Error.errorCode , properties.Error.message
| rename Dreqid as "Disclosure request id" , eocEnv as "Environment" , EOC_ResourceGroup as " Resource_Group" , activityName as "Activity Name" , pipelineName as "Pipeline Name" , operationName as "Operation Name" , pipelineRunId as "Run_Id" , level as "Level" , status as "STATUS" , category as "Category" , start as "Start-Time" , end_time as "End-Time" , properties.Error.errorCode as "Error-Code" , properties.Error.message as "Error-Message"
| sort -"Start-Time"

 

Real_captain_0-1706019257853.png

 

 

 

 

0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Find the difference between two timestamps by converting each into epoch (integer) format using the strptime function and then subtract them.

| eval eStartTime=strptime('Start-Time', "%Y-%m-%dT%H:%M:%S.%6N%Z")
| eval eEndTime=strptime('End-Time', "%Y-%m-%dT%H:%M:%S.%6N%Z")

P.S.  Avoid using hyphens in field names as they can be mis-interpreted as the subtraction operator.

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

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Find the difference between two timestamps by converting each into epoch (integer) format using the strptime function and then subtract them.

| eval eStartTime=strptime('Start-Time', "%Y-%m-%dT%H:%M:%S.%6N%Z")
| eval eEndTime=strptime('End-Time', "%Y-%m-%dT%H:%M:%S.%6N%Z")

P.S.  Avoid using hyphens in field names as they can be mis-interpreted as the subtraction operator.

---
If this reply helps you, Karma would be appreciated.
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...