Getting Data In

Calculate Age from 2 Timestamp fields


Hi All!

I have a field in my data which represents DOB in a YYYYMMDD format. I'm trying to compare that DOB Timestamp with another Timestamp field which represents the time the event was created. Same format YYYYMMDD. What I'm trying to determine is how old someone is when they were tested.

I've attempted to convert them both to epoch using eval, but it appears to only work on the first field.

index=test | eval DOB = strftime(Date_of_Birth, "%Y%m%d") | eval ICD = strftime(Instance_Creation_Date, "%Y%m%d") | eval diff = ('DOB' - 'ICD')

Anyone have a pointer?

As always. Thanks!

0 Karma


For the direction you're looking to convert, I think you want strptime rather than strftime.

0 Karma

Splunk Employee
Splunk Employee

The strftime function won't work for any data prior to the start of epoch in 1970. To do this properly, you will have to do your math discreetly. Check the accepted answer here for an approach.
You'll have to massage the RegEx a bit, because you don't have any separators between your date components. Something like this should work: rex field=Date_Of_Birth "(?<y>\d{4})(?<m>\d{2})(?<d>\d{2})"

0 Karma
Get Updates on the Splunk Community!

Index This | How many sides does a circle have?

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

Registration for Splunk University is Now Open!

Are you ready for an adventure in learning?   Brace yourselves because Splunk University is back, and it's ...

Splunkbase | Splunk Dashboard Examples App for SimpleXML End of Life

The Splunk Dashboard Examples App for SimpleXML will reach end of support on Dec 19, 2024, after which no new ...