<?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: Trouble with date conversion in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Trouble-with-date-conversion/m-p/615266#M213823</link>
    <description>&lt;P&gt;The &lt;FONT face="courier new,courier"&gt;convert&lt;/FONT&gt; command has options to control the format of the time string, but I prefer to use &lt;FONT face="courier new,courier"&gt;strftime&lt;/FONT&gt;.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|makeresults
|eval pubdate="2022-09-30,2021-08-31"
|makemv delim="," pubdate
|mvexpand pubdate
|eval epochtime=strptime(pubdate, "%Y-%m-%d") 
|eval 30days=relative_time(epochtime, "+30d")
|eval 30days=strftime('30days', "%Y-%m-%d")
|table pubdate, 30days&lt;/LI-CODE&gt;&lt;P&gt;I also used &lt;FONT face="courier new,courier"&gt;relative_time()&lt;/FONT&gt; to compute the new timestamp.&lt;/P&gt;&lt;P&gt;I didn't do it in my example, but try to avoid field names beginning with digits as they can confuse the parser.&amp;nbsp; For instance, the &lt;FONT face="courier new,courier"&gt;strftime&lt;/FONT&gt; call failed until I used single quotes around the first argument.&lt;/P&gt;</description>
    <pubDate>Thu, 29 Sep 2022 20:23:43 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2022-09-29T20:23:43Z</dc:date>
    <item>
      <title>Trouble with date conversion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trouble-with-date-conversion/m-p/615262#M213819</link>
      <description>&lt;P&gt;I need to create a field (30days) with a date 30 days from the date in a given field (pubdate). I believe I have that part working, but can't seem to get the date to convert to the format I want.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|makeresults
|eval pubdate="2022-09-30,2021-08-31"
|makemv delim="," pubdate
|mvexpand pubdate
|eval epochtime=strptime(pubdate, "%Y-%m-%d") 
|eval 30days=epochtime + 2592000
|convert ctime(30days)
|table pubdate, 30days&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Which produces:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;pubdate&lt;/TD&gt;&lt;TD width="50%"&gt;30days&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN&gt;2022-09-30&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;10/30/2022 00:00:00.000000&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;&lt;SPAN&gt;2021-08-31&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD width="50%"&gt;&lt;SPAN&gt;09/30/2021 00:00:00.000000&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All I want to do is to format the 30days date field the same was as pubdate -&amp;nbsp;"%Y-%m-%d". Everything I'm trying is producing an error.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 19:17:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trouble-with-date-conversion/m-p/615262#M213819</guid>
      <dc:creator>mistydennis</dc:creator>
      <dc:date>2022-09-29T19:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with date conversion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trouble-with-date-conversion/m-p/615264#M213821</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;have you tried&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;...
| convert timeformat="%Y-%m-%d" ctimes(30days)&lt;/LI-CODE&gt;&lt;P&gt;r. Ismo&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 20:18:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trouble-with-date-conversion/m-p/615264#M213821</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2022-09-29T20:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with date conversion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trouble-with-date-conversion/m-p/615266#M213823</link>
      <description>&lt;P&gt;The &lt;FONT face="courier new,courier"&gt;convert&lt;/FONT&gt; command has options to control the format of the time string, but I prefer to use &lt;FONT face="courier new,courier"&gt;strftime&lt;/FONT&gt;.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|makeresults
|eval pubdate="2022-09-30,2021-08-31"
|makemv delim="," pubdate
|mvexpand pubdate
|eval epochtime=strptime(pubdate, "%Y-%m-%d") 
|eval 30days=relative_time(epochtime, "+30d")
|eval 30days=strftime('30days', "%Y-%m-%d")
|table pubdate, 30days&lt;/LI-CODE&gt;&lt;P&gt;I also used &lt;FONT face="courier new,courier"&gt;relative_time()&lt;/FONT&gt; to compute the new timestamp.&lt;/P&gt;&lt;P&gt;I didn't do it in my example, but try to avoid field names beginning with digits as they can confuse the parser.&amp;nbsp; For instance, the &lt;FONT face="courier new,courier"&gt;strftime&lt;/FONT&gt; call failed until I used single quotes around the first argument.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 20:23:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trouble-with-date-conversion/m-p/615266#M213823</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-09-29T20:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with date conversion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trouble-with-date-conversion/m-p/615268#M213824</link>
      <description>&lt;P&gt;In most cases I also prefer to use strftime, but in adhoc &amp;nbsp;queries and especially with mv fields, it’s easier way to convert all values.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 20:36:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trouble-with-date-conversion/m-p/615268#M213824</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2022-09-29T20:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with date conversion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trouble-with-date-conversion/m-p/615269#M213825</link>
      <description>&lt;P&gt;Thank you,&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;&amp;nbsp;! I see you have answered MANY questions regarding date and timestamps here - maybe it's time for you to just write a book and help us all out &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 20:34:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trouble-with-date-conversion/m-p/615269#M213825</guid>
      <dc:creator>mistydennis</dc:creator>
      <dc:date>2022-09-29T20:34:15Z</dc:date>
    </item>
  </channel>
</rss>

