Getting Data In

how to subtract two date and time

Mohsin123
Path Finder

Hi ,

I have two date formats

i have to subtract to find the time duratiuon.Can anyone help me convert these to epoch time and then subtract

2018-03-29 10:54:55.0

Regards
Shraddha

Tags (2)
0 Karma

somesoni2
Revered Legend

Try like this

your current search with datefield1 and datefield2 which you want to subtract for duration
| eval duration_secs=strptime(datefield2,"%Y-%m-%d %H:%M:%S.%N")-strptime(datefield1,"%Y-%m-%d %H:%M:%S.%N")
| eval duration_str=tostring(duration,"duration")
0 Karma

sudosplunk
Motivator

Hello there,

Assuming you have your timestamps as start_date=2018-03-29 10:54:55.0 end_date=2018-04-29 10:54:55.0

Give this a shot,

your_base search 
     | eval start=strptime(start_date, "%Y-%m-%d %H:%M:%S.%N") 
     | eval end=strptime(end_date, "%Y-%m-%d %H:%M:%S.%N") 
     | eval difference = end - start 
     | table difference

Additionally, have a look at the below links for more details.

https://docs.splunk.com/Documentation/Splunk/7.1.2/SearchReference/Commontimeformatvariables
https://docs.splunk.com/Documentation/Splunk/7.1.2/SearchReference/Convert
http://docs.splunk.com/Documentation/Splunk/7.1.2/SearchReference/DateandTimeFunctions

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...