Getting Data In

How to calculate number of days between two epoch timestamps?

scheidelljm
Engager

I'm calculating the diff between two dates in different formats which is working, unless the "start date" and "end date" are the same. This results in an epoch diff of "0" and if you strftime a "0" into days, it thinks it's 31 days, but it should be 0 days. Is there a better java time variable to convert "0" in epoch into 0 days?

Examples:
STATUSDATE=19.04.2016
CREATIONDATE=19.04.2016

eval epochcreate=strptime(CREATIONDATE, "%d.%m.%Y") | eval epochstatus=strptime(STATUSDATE, "%d.%m.%Y") | eval diff = epochstatus-epochcreate |  eval resolutiontime = strftime(diff, "%d") 

This will give you a value for diff of 0.000000 and a value for resolutiontime of 31, expected resolutiontime should be 0.

0 Karma
1 Solution

scheidelljm
Engager

Nevermind, I'm an idiot. You can't strf diff. Diff is not an epoch date, it is a diff in seconds. This gives the expected result.
eval resolutiontime = diff/60/60/24

View solution in original post

scheidelljm
Engager

Nevermind, I'm an idiot. You can't strf diff. Diff is not an epoch date, it is a diff in seconds. This gives the expected result.
eval resolutiontime = diff/60/60/24

JeffLeshin
New Member

If it makes you feel any better - you're not the only idiot. Made the same mistake when I was wanting to create a nicer string out of a time difference in seconds. Thanks for posting your answer.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...