Other Usage

Is there a way to calculate Age by Date (Older than 50 years)?

peining
Observer

I am trying to calculate birth year and age, based on birthdate.

The following works, but only for dates within the last 50 years. There seems to be no output for birthdays > 50 years old. 

    eval APPLICANT_BIRTH_YEAR = strftime(strptime(APPLICANT_DOB, "%Y-%m-%d %H:%M:%S"), "%y")

Is there a way to do this properly?

Tags (1)
0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

@peining - Try this:

| eval APPLICANT_BIRTH_YEAR = substr(APPLICANT_DOB, 2, 2)

 

Kindly upvote if you find it useful!!!

0 Karma

yeahnah
Motivator

Hi @peining 

If the applicant DOB is provided as a string value anyway, then simply extract it from the string.  For example

| makeresults
| eval APPLICANT_DOB="1882-06-22 00:00:00"
      ,APPLICANT_BIRTH_YEAR=replace(APPLICANT_DOB, "-.*", "")

 Hope that helps

0 Karma

SanjayReddy
SplunkTrust
SplunkTrust

Hi @peining 

Unfortunately strptime can not convert years beofre 1971,

SanjayReddy_0-1682477186822.png

However, you can try solution provided by @ITWhisperer  ,  for similar case ,Hope folliowing post might help

https://community.splunk.com/t5/Splunk-Search/Problem-with-Date-Time-Manipulation-for-date-in-the-ye... 

0 Karma
Get Updates on the Splunk Community!

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...

Integrating Splunk Search API and Quarto to Create Reproducible Investigation ...

 Splunk is More Than Just the Web Console For Digital Forensics and Incident Response (DFIR) practitioners, ...

Congratulations to the 2025-2026 SplunkTrust!

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