Getting Data In

Calculate Age from 2 Timestamp fields

ctripod
Explorer

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

elliotproebstel
Champion

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

0 Karma

s2_splunk
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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

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