<?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 issue to insert date variable into customsql in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/issue-to-insert-date-variable-into-customsql/m-p/644053#M84098</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to set the start and end datetime as variable then insert into customsql. in method one below, JMP Alert of converting issue. When I simply hard coded the start and end date as variable, it run without issue. I check both the start and end date type in both method, both are string(). Event the custom sql after substitute into are identical. I cannot find out why the method one not working on date variable. Can someone help?? I really dont want to have to manually change the date everyday. How can I make method 1 works?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dadawasozo_0-1687268578976.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/53971iF4C451521773850D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dadawasozo_0-1687268578976.png" alt="dadawasozo_0-1687268578976.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;method 1 &amp;amp; 2&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//method 1 to define start and end  date (not working)
sdate= format(today()-inhours(24), "m/d/y");  //method 1
tstart = sdate || " 19:13:01 PM";// method 1

edate= format(today(), "m/d/y"); //method 1
tend = edate || " 12:13:00 AM"; //method 1

//method 2 to define start and end date (working)
tend= "06/19/2023 19:13:01 PM"; //method 2
tstart= "06/19/2023 12:13:00 AM";  //method2

Assign(sql_str,  "SELECT t1.[test], CAST(t2.[testplan ] AS INTEGER), bla bla bla
WHERE  (  (  ( t1.[end_time] &amp;gt;= &amp;amp;tstart  )  AND  ( t1.[end_time] &amp;lt;= &amp;amp;tend  )  )  ) ;"
);
substitute Into(sql_str, "&amp;amp;tstart", "'"||tstart ||"'");
substitute Into(sql_str, "&amp;amp;tend", "'"||tend ||"'");
dt = New SQL Query (Version(130), connection("mydatabaseinfor"), QueryName("mysqlname" ), CustomSQL(sql_str)) &amp;lt;&amp;lt; Run Foreground;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 20 Jun 2023 13:55:01 GMT</pubDate>
    <dc:creator>dadawasozo</dc:creator>
    <dc:date>2023-06-20T13:55:01Z</dc:date>
    <item>
      <title>issue to insert date variable into customsql</title>
      <link>https://community.jmp.com/t5/Discussions/issue-to-insert-date-variable-into-customsql/m-p/644053#M84098</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to set the start and end datetime as variable then insert into customsql. in method one below, JMP Alert of converting issue. When I simply hard coded the start and end date as variable, it run without issue. I check both the start and end date type in both method, both are string(). Event the custom sql after substitute into are identical. I cannot find out why the method one not working on date variable. Can someone help?? I really dont want to have to manually change the date everyday. How can I make method 1 works?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dadawasozo_0-1687268578976.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/53971iF4C451521773850D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dadawasozo_0-1687268578976.png" alt="dadawasozo_0-1687268578976.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;method 1 &amp;amp; 2&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//method 1 to define start and end  date (not working)
sdate= format(today()-inhours(24), "m/d/y");  //method 1
tstart = sdate || " 19:13:01 PM";// method 1

edate= format(today(), "m/d/y"); //method 1
tend = edate || " 12:13:00 AM"; //method 1

//method 2 to define start and end date (working)
tend= "06/19/2023 19:13:01 PM"; //method 2
tstart= "06/19/2023 12:13:00 AM";  //method2

Assign(sql_str,  "SELECT t1.[test], CAST(t2.[testplan ] AS INTEGER), bla bla bla
WHERE  (  (  ( t1.[end_time] &amp;gt;= &amp;amp;tstart  )  AND  ( t1.[end_time] &amp;lt;= &amp;amp;tend  )  )  ) ;"
);
substitute Into(sql_str, "&amp;amp;tstart", "'"||tstart ||"'");
substitute Into(sql_str, "&amp;amp;tend", "'"||tend ||"'");
dt = New SQL Query (Version(130), connection("mydatabaseinfor"), QueryName("mysqlname" ), CustomSQL(sql_str)) &amp;lt;&amp;lt; Run Foreground;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Jun 2023 13:55:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/issue-to-insert-date-variable-into-customsql/m-p/644053#M84098</guid>
      <dc:creator>dadawasozo</dc:creator>
      <dc:date>2023-06-20T13:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: issue to insert date variable into customsql</title>
      <link>https://community.jmp.com/t5/Discussions/issue-to-insert-date-variable-into-customsql/m-p/644233#M84100</link>
      <description>&lt;P&gt;Does your method1 provide you with correct strings? It could be that the date is formatted incorrectly.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

sdate = today()-inhours(24);
m = Month(sdate);
y = Year(sdate);
d = Day(sdate);
sdate = Eval Insert("^m^/^d^/^y^");
tstart = sdate || " 19:13:01 PM";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 15:55:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/issue-to-insert-date-variable-into-customsql/m-p/644233#M84100</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-06-20T15:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: issue to insert date variable into customsql</title>
      <link>https://community.jmp.com/t5/Discussions/issue-to-insert-date-variable-into-customsql/m-p/644265#M84105</link>
      <description>&lt;P&gt;the method1 give the same identical string as method2 when I do show().&lt;/P&gt;&lt;P&gt;I tried your method, and still getting same error.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 17:10:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/issue-to-insert-date-variable-into-customsql/m-p/644265#M84105</guid>
      <dc:creator>dadawasozo</dc:creator>
      <dc:date>2023-06-20T17:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: issue to insert date variable into customsql</title>
      <link>https://community.jmp.com/t5/Discussions/issue-to-insert-date-variable-into-customsql/m-p/644287#M84108</link>
      <description>&lt;P&gt;Checking your script again, you have tstart and tend different on method1 and method2. Maybe it is causing issues during the query?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 18:38:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/issue-to-insert-date-variable-into-customsql/m-p/644287#M84108</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-06-20T18:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: issue to insert date variable into customsql</title>
      <link>https://community.jmp.com/t5/Discussions/issue-to-insert-date-variable-into-customsql/m-p/644300#M84110</link>
      <description>&lt;P&gt;dont think so, I tried same as method 2 but still have same issue.&amp;nbsp;&lt;BR /&gt;could it be bug in jmp pro 16.2?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 18:48:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/issue-to-insert-date-variable-into-customsql/m-p/644300#M84110</guid>
      <dc:creator>dadawasozo</dc:creator>
      <dc:date>2023-06-20T18:48:17Z</dc:date>
    </item>
  </channel>
</rss>

