<?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: DBConnect, $earliest$ and $latest$ in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/DBConnect-earliest-and-latest/m-p/170189#M186321</link>
    <description>&lt;P&gt;The $earliest$ and $latest$ variables are in epoch time, so I just wrote a stored procedure that converts it to DATE and runs the query based on that.&lt;/P&gt;

&lt;P&gt;SQL:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Create Procedure [dbo].[procedureName]
    @EpochBeginDate INT,
    @EpochEndDate INT
AS
BEGIN
Set NOCOUNT ON

DECLARE @BeginDate DATE;
DECLARE @EndDate DATE;
IF @EpochBeginDate IS NULL
BEGIN
    --Defaulting to three months ago
    SELECT @BeginDate = DATEADD(MONTH, -3, GETDATE()); 
    END
ELSE 
BEGIN
    --adding EpochBeginDate to 01-01-1970
    SELECT @BeginDate = DATEADD(s, @EpochBeginDate, '19700101'); 
    END

IF @EpochEndDate IS NULL
BEGIN
    --Defaulting to Today
    SELECT @EndDate = GETDATE(); 
    END
ELSE 
BEGIN
    --adding EpochEndDate to 01-01-1970
    SELECT @EndDate = DATEADD(s, @EpochEndDate, '19700101'); 
    END


-- Insert statements for procedure here
SELECT
FROM
WHERE
END
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 20 May 2014 20:40:36 GMT</pubDate>
    <dc:creator>devicenul1</dc:creator>
    <dc:date>2014-05-20T20:40:36Z</dc:date>
    <item>
      <title>DBConnect, $earliest$ and $latest$</title>
      <link>https://community.splunk.com/t5/Splunk-Search/DBConnect-earliest-and-latest/m-p/170186#M186318</link>
      <description>&lt;P&gt;Anyway to pass the earliest and latest variables from a time range picker to the DB Connect Query command in a specified format?&lt;/P&gt;

&lt;P&gt;for example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|dbquery LiveDB "select * from table between '$earliest$="%Y-%m-%d"' and '$latest$="%Y-%m-%d"'"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Because DB Query needs to be the first command of a search I've tried doing the eval's as a subsearch, something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|dbquery LiveDB "select * from table between '$early$' and '$late$' [eval e=$earliest$ | eval l=$latest$ | eval early=strptime(e, "%Y-%m-%d") | eval late=strptime(l, "%Y-%m-%d") ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but doing that seems to just put it into a "Search is waiting for input" state ... any ideas?&lt;/P&gt;</description>
      <pubDate>Mon, 19 May 2014 17:57:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/DBConnect-earliest-and-latest/m-p/170186#M186318</guid>
      <dc:creator>devicenul1</dc:creator>
      <dc:date>2014-05-19T17:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: DBConnect, $earliest$ and $latest$</title>
      <link>https://community.splunk.com/t5/Splunk-Search/DBConnect-earliest-and-latest/m-p/170187#M186319</link>
      <description>&lt;P&gt;Hi, I have the same problem. The only workaround I could do is to pipe the results and compare the time like this: "| where date_field &amp;gt; relative_time(now(),"-1mon@mon")".&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:40:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/DBConnect-earliest-and-latest/m-p/170187#M186319</guid>
      <dc:creator>gfreitas</dc:creator>
      <dc:date>2020-09-28T16:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: DBConnect, $earliest$ and $latest$</title>
      <link>https://community.splunk.com/t5/Splunk-Search/DBConnect-earliest-and-latest/m-p/170188#M186320</link>
      <description>&lt;P&gt;Ahh I see, that's a good workaround but I'd really like to limit my searches out of SQL to only relevant data. This seems like such a simple thing. I've exhausted all research into figuring out how to do this either as an inline search or through the xml dashboards. I've moved my research into using the HTML dashboards and trying to catch this via the javascript. I'll update this thread if I make any progress.&lt;/P&gt;</description>
      <pubDate>Tue, 20 May 2014 15:10:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/DBConnect-earliest-and-latest/m-p/170188#M186320</guid>
      <dc:creator>devicenul1</dc:creator>
      <dc:date>2014-05-20T15:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: DBConnect, $earliest$ and $latest$</title>
      <link>https://community.splunk.com/t5/Splunk-Search/DBConnect-earliest-and-latest/m-p/170189#M186321</link>
      <description>&lt;P&gt;The $earliest$ and $latest$ variables are in epoch time, so I just wrote a stored procedure that converts it to DATE and runs the query based on that.&lt;/P&gt;

&lt;P&gt;SQL:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Create Procedure [dbo].[procedureName]
    @EpochBeginDate INT,
    @EpochEndDate INT
AS
BEGIN
Set NOCOUNT ON

DECLARE @BeginDate DATE;
DECLARE @EndDate DATE;
IF @EpochBeginDate IS NULL
BEGIN
    --Defaulting to three months ago
    SELECT @BeginDate = DATEADD(MONTH, -3, GETDATE()); 
    END
ELSE 
BEGIN
    --adding EpochBeginDate to 01-01-1970
    SELECT @BeginDate = DATEADD(s, @EpochBeginDate, '19700101'); 
    END

IF @EpochEndDate IS NULL
BEGIN
    --Defaulting to Today
    SELECT @EndDate = GETDATE(); 
    END
ELSE 
BEGIN
    --adding EpochEndDate to 01-01-1970
    SELECT @EndDate = DATEADD(s, @EpochEndDate, '19700101'); 
    END


-- Insert statements for procedure here
SELECT
FROM
WHERE
END
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 May 2014 20:40:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/DBConnect-earliest-and-latest/m-p/170189#M186321</guid>
      <dc:creator>devicenul1</dc:creator>
      <dc:date>2014-05-20T20:40:36Z</dc:date>
    </item>
  </channel>
</rss>

