<?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 Custom Date Format in JSL Script (For Query Builder) in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Custom-Date-Format-in-JSL-Script-For-Query-Builder/m-p/518677#M74478</link>
    <description>&lt;P&gt;Overall Goal: Create a query in Query Builder that filters on a date time column only pulling data from the last 7 days of the current time. I am trying to use a custom expression in Query Builder to do this. Ideally it would just be the following in the custom expression filter but it results in no data pulled.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;t1.TimeCol &amp;gt;= format((Today() - InDays(7)), "m/d/y h:m:s")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It appears Query Builder takes a specific date time format for its WHERE statement, 'y-m-d h:m:s' (i.e&amp;nbsp;'2022-07-07 11:13:55'),&amp;nbsp; for which JMP doesn't have a built in format for. Therefore I created a custom date format shown below using&amp;nbsp;&lt;A href="https://www.jmp.com/support/help/14-2/custom-transform-example.shtml#1660430" target="_self"&gt;this example&lt;/A&gt;. In a data table it converts a date time column to the custom format as expected. I am struggling to call the format in jsl code though as I get a "Unknown format: myNamespace:QueryDate" error. Any insight? Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;print(format(Today(), "m/d/y"));
print(format(Today(), "myNamespace:QueryDate"));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Custom format:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Add Custom Functions(
New Custom Function(
"myNamespace",
"QueryDate",
Function( {inputVar},
{Default Local},
Char( Year( inputVar ) ) || "-" || Char( Month( inputVar ) ) || "-" ||
Char( Day( inputVar ) ) || " " ||
Char(Hour(inputVar)) || ":" || Char(Minute(inputVar)) || ":" || Char(Second(inputVar))

),
&amp;lt;&amp;lt;Description(
"Date format for query builder y-d-m h:m:s"
),
&amp;lt;&amp;lt;Custom Format Category( 1 )
)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2023 17:03:43 GMT</pubDate>
    <dc:creator>bittnere</dc:creator>
    <dc:date>2023-06-09T17:03:43Z</dc:date>
    <item>
      <title>Custom Date Format in JSL Script (For Query Builder)</title>
      <link>https://community.jmp.com/t5/Discussions/Custom-Date-Format-in-JSL-Script-For-Query-Builder/m-p/518677#M74478</link>
      <description>&lt;P&gt;Overall Goal: Create a query in Query Builder that filters on a date time column only pulling data from the last 7 days of the current time. I am trying to use a custom expression in Query Builder to do this. Ideally it would just be the following in the custom expression filter but it results in no data pulled.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;t1.TimeCol &amp;gt;= format((Today() - InDays(7)), "m/d/y h:m:s")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It appears Query Builder takes a specific date time format for its WHERE statement, 'y-m-d h:m:s' (i.e&amp;nbsp;'2022-07-07 11:13:55'),&amp;nbsp; for which JMP doesn't have a built in format for. Therefore I created a custom date format shown below using&amp;nbsp;&lt;A href="https://www.jmp.com/support/help/14-2/custom-transform-example.shtml#1660430" target="_self"&gt;this example&lt;/A&gt;. In a data table it converts a date time column to the custom format as expected. I am struggling to call the format in jsl code though as I get a "Unknown format: myNamespace:QueryDate" error. Any insight? Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;print(format(Today(), "m/d/y"));
print(format(Today(), "myNamespace:QueryDate"));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Custom format:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Add Custom Functions(
New Custom Function(
"myNamespace",
"QueryDate",
Function( {inputVar},
{Default Local},
Char( Year( inputVar ) ) || "-" || Char( Month( inputVar ) ) || "-" ||
Char( Day( inputVar ) ) || " " ||
Char(Hour(inputVar)) || ":" || Char(Minute(inputVar)) || ":" || Char(Second(inputVar))

),
&amp;lt;&amp;lt;Description(
"Date format for query builder y-d-m h:m:s"
),
&amp;lt;&amp;lt;Custom Format Category( 1 )
)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 17:03:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Custom-Date-Format-in-JSL-Script-For-Query-Builder/m-p/518677#M74478</guid>
      <dc:creator>bittnere</dc:creator>
      <dc:date>2023-06-09T17:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Date Format in JSL Script (For Query Builder)</title>
      <link>https://community.jmp.com/t5/Discussions/Custom-Date-Format-in-JSL-Script-For-Query-Builder/m-p/518825#M74488</link>
      <description>&lt;P&gt;If you compare a datetime column at database, you need a datetime value for the comparison, but format returns a string. So this will not work so far as I can see. You would need to convert the datetime string at database to a datetime value.&lt;/P&gt;
&lt;P&gt;But for your task you can avoid this problem, by simply taking the current date from the database and subtracting some days, and implement this as a custom expression in the Query Builder,&lt;/P&gt;
&lt;P&gt;but the syntax will depend on database.&lt;/P&gt;
&lt;P&gt;For ANSI it may look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;t1.datetime &amp;gt; addday(now(), -7)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and for Oracle it may look like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;t1.datetime &amp;gt; sysdate - 7&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jul 2022 22:08:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Custom-Date-Format-in-JSL-Script-For-Query-Builder/m-p/518825#M74488</guid>
      <dc:creator>Georg</dc:creator>
      <dc:date>2022-07-07T22:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Date Format in JSL Script (For Query Builder)</title>
      <link>https://community.jmp.com/t5/Discussions/Custom-Date-Format-in-JSL-Script-For-Query-Builder/m-p/518925#M74497</link>
      <description>&lt;P&gt;or see other posts:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.jmp.com/t5/Discussions/SQL-query-script-problem-with-date-format/m-p/453397#M70033" target="_blank"&gt;Solved: SQL query script problem with date format - JMP User Community&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.jmp.com/t5/Discussions/Interactive-date-selection-and-filtering-by-SQL/m-p/48833" target="_blank"&gt;Solved: Interactive date selection and filtering by SQL - JMP User Community&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 06:13:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Custom-Date-Format-in-JSL-Script-For-Query-Builder/m-p/518925#M74497</guid>
      <dc:creator>Georg</dc:creator>
      <dc:date>2022-07-08T06:13:46Z</dc:date>
    </item>
  </channel>
</rss>

