<?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: Splunk DB Connect:  How to resolve error &amp;quot;Conversion failed when converting date and/or time from character string&amp;quot; for my SQL query? in All Apps and Add-ons</title>
    <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-DB-Connect-How-to-resolve-error-quot-Conversion-failed/m-p/275395#M32166</link>
    <description>&lt;P&gt;But wait, your example here isn't the same example as what you gave.  &lt;/P&gt;

&lt;P&gt;This example appears compliant (assuming SQL 2012ish, which may or may not be right) with it's &lt;A href="https://msdn.microsoft.com/en-us/library/ms187928.aspx"&gt;convert requirements&lt;/A&gt;, specifically that it has "+13:00" whereas your original example doesn't have the colon and is "+1200".&lt;/P&gt;

&lt;P&gt;This is probably fixable, but first could you confirm one wasn't a typo?  &lt;/P&gt;

&lt;P&gt;(Fixable - I'm not sure the best method.  You could potentially manually substr all the bits and pieces into a new datetime, or it may be easier to substring out the first 90%, concatenate a colon into it and tack on the final two digits as string manipulation and THEN do your convert).&lt;/P&gt;</description>
    <pubDate>Fri, 28 Oct 2016 15:45:13 GMT</pubDate>
    <dc:creator>Richfez</dc:creator>
    <dc:date>2016-10-28T15:45:13Z</dc:date>
    <item>
      <title>Splunk DB Connect:  How to resolve error "Conversion failed when converting date and/or time from character string" for my SQL query?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-DB-Connect-How-to-resolve-error-quot-Conversion-failed/m-p/275393#M32164</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;

&lt;P&gt;Any one has experienced this in ingesting IBM IPS Database?&lt;/P&gt;

&lt;P&gt;I tried to write a SQL query to return some events from the SensorDataAVP1 table. But the time format is actually a string value like this: &lt;CODE&gt;2015-05-09T16:08:47+1200&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;I did some Googling, it is ISO8601 format with time zone Z (aka 127).  But whatever I try, I always get this error "Conversion failed when converting date and/or time from character string".&lt;/P&gt;

&lt;P&gt;The original string is in nvarchar format. So I converted it to varchar format first before converting it to datetime.&lt;/P&gt;

&lt;P&gt;And seems the SQL datetime format doesn't support timezone, so I use datetimeoffset instead.&lt;/P&gt;

&lt;P&gt;Here is my convert string: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;convert(datetimeoffset, convert(varchar(40),time),127) AS time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any thoughts?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2016 04:24:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-DB-Connect-How-to-resolve-error-quot-Conversion-failed/m-p/275393#M32164</guid>
      <dc:creator>season88481</dc:creator>
      <dc:date>2016-10-28T04:24:24Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk DB Connect:  How to resolve error "Conversion failed when converting date and/or time from character string" for my SQL query?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-DB-Connect-How-to-resolve-error-quot-Conversion-failed/m-p/275394#M32165</link>
      <description>&lt;P&gt;And I've tried replicating the conversion on my SSMS, which works perfectly:&lt;/P&gt;

&lt;P&gt;declare @c nvarchar(50) = '2015-02-28T01:38:28+13:00'&lt;BR /&gt;
select convert(datetimeoffset,convert(varchar(50),@c,127),127)&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2016 04:28:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-DB-Connect-How-to-resolve-error-quot-Conversion-failed/m-p/275394#M32165</guid>
      <dc:creator>season88481</dc:creator>
      <dc:date>2016-10-28T04:28:02Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk DB Connect:  How to resolve error "Conversion failed when converting date and/or time from character string" for my SQL query?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-DB-Connect-How-to-resolve-error-quot-Conversion-failed/m-p/275395#M32166</link>
      <description>&lt;P&gt;But wait, your example here isn't the same example as what you gave.  &lt;/P&gt;

&lt;P&gt;This example appears compliant (assuming SQL 2012ish, which may or may not be right) with it's &lt;A href="https://msdn.microsoft.com/en-us/library/ms187928.aspx"&gt;convert requirements&lt;/A&gt;, specifically that it has "+13:00" whereas your original example doesn't have the colon and is "+1200".&lt;/P&gt;

&lt;P&gt;This is probably fixable, but first could you confirm one wasn't a typo?  &lt;/P&gt;

&lt;P&gt;(Fixable - I'm not sure the best method.  You could potentially manually substr all the bits and pieces into a new datetime, or it may be easier to substring out the first 90%, concatenate a colon into it and tack on the final two digits as string manipulation and THEN do your convert).&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2016 15:45:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-DB-Connect-How-to-resolve-error-quot-Conversion-failed/m-p/275395#M32166</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2016-10-28T15:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk DB Connect:  How to resolve error "Conversion failed when converting date and/or time from character string" for my SQL query?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-DB-Connect-How-to-resolve-error-quot-Conversion-failed/m-p/275396#M32167</link>
      <description>&lt;P&gt;Hi Rich,&lt;/P&gt;

&lt;P&gt;Thanks for your reminder. I did make a mistake there. The timezone part of the original string is something like '+1300' not '+13:00'&lt;/P&gt;

&lt;P&gt;Do you think I can convert the original string to a format like '2015-02-28T01:38:28+13:00', then use the same SQL query to fetch events?&lt;/P&gt;

&lt;P&gt;Thanks a lot for your reply. Much appreciated! &lt;/P&gt;</description>
      <pubDate>Sun, 30 Oct 2016 20:54:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-DB-Connect-How-to-resolve-error-quot-Conversion-failed/m-p/275396#M32167</guid>
      <dc:creator>season88481</dc:creator>
      <dc:date>2016-10-30T20:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk DB Connect:  How to resolve error "Conversion failed when converting date and/or time from character string" for my SQL query?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-DB-Connect-How-to-resolve-error-quot-Conversion-failed/m-p/275397#M32168</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;

&lt;P&gt;I've gave up converting time by using SQL query. Cause I am not a sql master, so it would be a waste of time to research a solution for that.&lt;/P&gt;

&lt;P&gt;So firstly in the sql query, I renamed the time column as fieldname 'time'.&lt;/P&gt;

&lt;P&gt;Then ingested the time in a string format directly to Splunk. Then in the props.conf, I used a little of regex to solve the problem.&lt;/P&gt;

&lt;P&gt;Here is the sample of my props.conf stanza:&lt;BR /&gt;
TIME_PREFIX = time="&lt;BR /&gt;
TIME_FORMAT = %Y-%m-%dT%H:%M:%S&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:41:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-DB-Connect-How-to-resolve-error-quot-Conversion-failed/m-p/275397#M32168</guid>
      <dc:creator>season88481</dc:creator>
      <dc:date>2020-09-29T11:41:48Z</dc:date>
    </item>
  </channel>
</rss>

