<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Calculate Age from 2 Timestamp fields in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Calculate-Age-from-2-Timestamp-fields/m-p/322108#M60041</link>
    <description>&lt;P&gt;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 &lt;A href="https://answers.splunk.com/answers/338613/how-to-work-out-the-age-of-a-user-based-on-date-of.html"&gt;accepted answer here&lt;/A&gt; for an approach.&lt;BR /&gt;
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: &lt;CODE&gt;rex field=Date_Of_Birth "(?&amp;lt;y&amp;gt;\d{4})(?&amp;lt;m&amp;gt;\d{2})(?&amp;lt;d&amp;gt;\d{2})"&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Oct 2017 19:20:43 GMT</pubDate>
    <dc:creator>s2_splunk</dc:creator>
    <dc:date>2017-10-20T19:20:43Z</dc:date>
    <item>
      <title>Calculate Age from 2 Timestamp fields</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Calculate-Age-from-2-Timestamp-fields/m-p/322107#M60040</link>
      <description>&lt;P&gt;Hi All!&lt;/P&gt;

&lt;P&gt;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.&lt;/P&gt;

&lt;P&gt;I've attempted to convert them both to epoch using eval, but it appears to only work on the first field.&lt;/P&gt;

&lt;P&gt;index=test | eval DOB = strftime(Date_of_Birth, "%Y%m%d") | eval ICD = strftime(Instance_Creation_Date, "%Y%m%d") | eval diff = ('DOB' - 'ICD')&lt;/P&gt;

&lt;P&gt;Anyone have a pointer?&lt;/P&gt;

&lt;P&gt;As always. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:22:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Calculate-Age-from-2-Timestamp-fields/m-p/322107#M60040</guid>
      <dc:creator>ctripod</dc:creator>
      <dc:date>2020-09-29T16:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Age from 2 Timestamp fields</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Calculate-Age-from-2-Timestamp-fields/m-p/322108#M60041</link>
      <description>&lt;P&gt;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 &lt;A href="https://answers.splunk.com/answers/338613/how-to-work-out-the-age-of-a-user-based-on-date-of.html"&gt;accepted answer here&lt;/A&gt; for an approach.&lt;BR /&gt;
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: &lt;CODE&gt;rex field=Date_Of_Birth "(?&amp;lt;y&amp;gt;\d{4})(?&amp;lt;m&amp;gt;\d{2})(?&amp;lt;d&amp;gt;\d{2})"&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 19:20:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Calculate-Age-from-2-Timestamp-fields/m-p/322108#M60041</guid>
      <dc:creator>s2_splunk</dc:creator>
      <dc:date>2017-10-20T19:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Age from 2 Timestamp fields</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Calculate-Age-from-2-Timestamp-fields/m-p/322109#M60042</link>
      <description>&lt;P&gt;For the direction you're looking to convert, I think you want &lt;CODE&gt;strptime&lt;/CODE&gt; rather than &lt;CODE&gt;strftime&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 19:32:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Calculate-Age-from-2-Timestamp-fields/m-p/322109#M60042</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2017-10-20T19:32:07Z</dc:date>
    </item>
  </channel>
</rss>

