<?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: JSL: Extract day of week from datetime field (scripting) in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JSL-Extract-day-of-week-from-datetime-field-scripting/m-p/215283#M43023</link>
    <description>&lt;P&gt;If needed, use 'Help &amp;gt; Scripting Index' to find more details of how the commands work;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;NamesDefaultToHere(1);

// Make a table of random dates
n = 50;
startDate = Date DMY( 01, 1, 2016 );
endDate = Date DMY( 12, 10, 2016 );
dates = Sort Ascending( J( n, 1, Random Integer(startDate, endDate) ) );
dt = New Table( "Dates",
			New Column( "Random dates", Numeric, "Continuous", Format( "ddMonyyyy h:m", 35 ), Set Values( dates )),
		);

// Add a formula for the day of the week
nc = dt &amp;lt;&amp;lt; New Column( "Day of the week",
						Numeric,
						"Continuous",
						Format( "Best", 12 ),
						Formula( Day Of Week( :Random dates ) ),
						Value Labels(
							{1 = "Sunday", 2 = "Monday", 3 = "Tuesday", 4 = "Wednesday", 5 = "Thursday",
							6 = "Friday", 7 = "Saturday"}
						),
						Use Value Labels( 1 ),
					);

// Make a subset table
r = dt &amp;lt;&amp;lt; getRowsWhere(:Day of the week == 7 | :Day of the week == 1);
dt2 = dt &amp;lt;&amp;lt; Subset(rows(r), LinkToOriginalDataTable(1));
dt2 &amp;lt;&amp;lt; setName("Weekend Dates");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jun 2019 08:44:09 GMT</pubDate>
    <dc:creator>ian_jmp</dc:creator>
    <dc:date>2019-06-28T08:44:09Z</dc:date>
    <item>
      <title>JSL: Extract day of week from datetime field (scripting)</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Extract-day-of-week-from-datetime-field-scripting/m-p/215228#M43008</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a field START_TIME (datetime format), e.g.&lt;/P&gt;&lt;P&gt;15.06.2019 6:05&lt;/P&gt;&lt;P&gt;16.06.2019 8:12&lt;/P&gt;&lt;P&gt;17.06.2019 7:01 etc.&lt;/P&gt;&lt;P&gt;I would like to keep all days that are Saturdays and Sundays.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I imagine, by extracting I would receive a value like&lt;/P&gt;&lt;P&gt;START_TIME&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SAT_SUN&lt;/P&gt;&lt;P&gt;15.06.2019 6:05&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&lt;/P&gt;&lt;P&gt;16.06.2019 8:12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;17.06.2019 7:01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;Then I just use keep 1s and 7s, right.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would I do that with JSL script?&lt;/P&gt;&lt;P&gt;I tried approaches like&lt;/P&gt;&lt;P&gt;dt &amp;lt;&amp;lt; New Column ("SAT_SUN",numeric,format(day of week(:START_TIME),"datetime")) ;&lt;/P&gt;&lt;P&gt;that don't seem to work.&lt;/P&gt;&lt;P&gt;Any idea?&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;&lt;P&gt;Newbie&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 04:55:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Extract-day-of-week-from-datetime-field-scripting/m-p/215228#M43008</guid>
      <dc:creator>Newbie2Jumpie</dc:creator>
      <dc:date>2019-06-28T04:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: JSL: Extract day of week from datetime field (scripting)</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Extract-day-of-week-from-datetime-field-scripting/m-p/215261#M43013</link>
      <description>Just qick idea (as I have to leave in a minute): If you want to keep all values you can just use the filter command and exclude all the others not matching SAT/SUN. &lt;BR /&gt;If you really want to remove the rows not equal to  SAT/SUN then use SELECT WHERE and then delete rows.MAy someone can write a demo script :)&lt;/img&gt;</description>
      <pubDate>Fri, 28 Jun 2019 07:10:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Extract-day-of-week-from-datetime-field-scripting/m-p/215261#M43013</guid>
      <dc:creator>martindemel</dc:creator>
      <dc:date>2019-06-28T07:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: JSL: Extract day of week from datetime field (scripting)</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Extract-day-of-week-from-datetime-field-scripting/m-p/215280#M43021</link>
      <description>&lt;P&gt;There is no need to create a new column to do what you want.&amp;nbsp; Here is a simple script that does what you asked for:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Aircraft Incidents.jmp" );

dt &amp;lt;&amp;lt; select where( Day Of Week( :Event Date ) == 1 | Day Of Week( :Event Date ) == 7 );

dtsub = dt &amp;lt;&amp;lt; subset( selected rows( 1 ), selected columns( 0 ) );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Jun 2019 08:34:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Extract-day-of-week-from-datetime-field-scripting/m-p/215280#M43021</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2019-06-28T08:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: JSL: Extract day of week from datetime field (scripting)</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Extract-day-of-week-from-datetime-field-scripting/m-p/215283#M43023</link>
      <description>&lt;P&gt;If needed, use 'Help &amp;gt; Scripting Index' to find more details of how the commands work;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;NamesDefaultToHere(1);

// Make a table of random dates
n = 50;
startDate = Date DMY( 01, 1, 2016 );
endDate = Date DMY( 12, 10, 2016 );
dates = Sort Ascending( J( n, 1, Random Integer(startDate, endDate) ) );
dt = New Table( "Dates",
			New Column( "Random dates", Numeric, "Continuous", Format( "ddMonyyyy h:m", 35 ), Set Values( dates )),
		);

// Add a formula for the day of the week
nc = dt &amp;lt;&amp;lt; New Column( "Day of the week",
						Numeric,
						"Continuous",
						Format( "Best", 12 ),
						Formula( Day Of Week( :Random dates ) ),
						Value Labels(
							{1 = "Sunday", 2 = "Monday", 3 = "Tuesday", 4 = "Wednesday", 5 = "Thursday",
							6 = "Friday", 7 = "Saturday"}
						),
						Use Value Labels( 1 ),
					);

// Make a subset table
r = dt &amp;lt;&amp;lt; getRowsWhere(:Day of the week == 7 | :Day of the week == 1);
dt2 = dt &amp;lt;&amp;lt; Subset(rows(r), LinkToOriginalDataTable(1));
dt2 &amp;lt;&amp;lt; setName("Weekend Dates");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 08:44:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Extract-day-of-week-from-datetime-field-scripting/m-p/215283#M43023</guid>
      <dc:creator>ian_jmp</dc:creator>
      <dc:date>2019-06-28T08:44:09Z</dc:date>
    </item>
  </channel>
</rss>

