<?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 strptime calculation  not working correctly with / but works with - timeformat in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/strptime-calculation-not-working-correctly-with-but-works-with/m-p/672423#M230320</link>
    <description>&lt;P&gt;Hi, communities,&lt;/P&gt;&lt;P&gt;I am doing a calculation or eval command.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval dormancy=if(last_login="(never)",round((now()-strptime(created,"%Y-%m-%d"))/86400),round((now()-strptime(last_login,"%Y-%m-%d"))/86400)) &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above calculate dormancy number correctly but, soon as I change the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval dormancy=if(last_login="(never)",round((now()-strptime(created,"%Y/%m/%d"))/86400),round((now()-strptime(last_login,"%Y/%m/%d"))/86400)) &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from "-" to "/" strptime doesn't calculate the dormancy days.&amp;nbsp; Is this limit of strptime or am I doing something wrong?&lt;/P&gt;</description>
    <pubDate>Wed, 20 Dec 2023 16:04:08 GMT</pubDate>
    <dc:creator>youngsuh</dc:creator>
    <dc:date>2023-12-20T16:04:08Z</dc:date>
    <item>
      <title>strptime calculation  not working correctly with / but works with - timeformat</title>
      <link>https://community.splunk.com/t5/Splunk-Search/strptime-calculation-not-working-correctly-with-but-works-with/m-p/672423#M230320</link>
      <description>&lt;P&gt;Hi, communities,&lt;/P&gt;&lt;P&gt;I am doing a calculation or eval command.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval dormancy=if(last_login="(never)",round((now()-strptime(created,"%Y-%m-%d"))/86400),round((now()-strptime(last_login,"%Y-%m-%d"))/86400)) &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above calculate dormancy number correctly but, soon as I change the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval dormancy=if(last_login="(never)",round((now()-strptime(created,"%Y/%m/%d"))/86400),round((now()-strptime(last_login,"%Y/%m/%d"))/86400)) &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from "-" to "/" strptime doesn't calculate the dormancy days.&amp;nbsp; Is this limit of strptime or am I doing something wrong?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 16:04:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/strptime-calculation-not-working-correctly-with-but-works-with/m-p/672423#M230320</guid>
      <dc:creator>youngsuh</dc:creator>
      <dc:date>2023-12-20T16:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: strptime calculation  not working correctly with / but works with - timeformat</title>
      <link>https://community.splunk.com/t5/Splunk-Search/strptime-calculation-not-working-correctly-with-but-works-with/m-p/672426#M230321</link>
      <description>&lt;P&gt;It sounds like you timestamps "created" and "last_login" have the format "%Y-%m-%d" in the events.&lt;BR /&gt;&lt;BR /&gt;Trying to convert them to epoch using a different format will not work. For example&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dtburrows3_0-1703089049861.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/28606iB5B24AC8D6174A2C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dtburrows3_0-1703089049861.png" alt="dtburrows3_0-1703089049861.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;If you have a situations where your events have these field in a mixture of both formats, maybe you could adjust your eval to be something more like this?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval
        dormancy=if(
            last_login="(never)",
                round((now()-case(match(created, "^\d{4}\-\d{2}\-\d{2}"), strptime(created,"%Y-%m-%d"), match(created, "^\d{4}\/\d{2}\/\d{2}"), strptime(created,"%Y/%m/%d")))/86400),
                round((now()-case(match(last_login, "^\d{4}\-\d{2}\-\d{2}"), strptime(last_login,"%Y-%m-%d"), match(last_login, "^\d{4}\/\d{2}\/\d{2}"), strptime(last_login,"%Y/%m/%d")))/86400)
            )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;This seem to extract both formats properly&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dtburrows3_1-1703089297540.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/28607i067E6F6AAA530F70/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dtburrows3_1-1703089297540.png" alt="dtburrows3_1-1703089297540.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 16:21:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/strptime-calculation-not-working-correctly-with-but-works-with/m-p/672426#M230321</guid>
      <dc:creator>dtburrows3</dc:creator>
      <dc:date>2023-12-20T16:21:44Z</dc:date>
    </item>
  </channel>
</rss>

