cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-215228%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EJSL%3A%20estratto%20giorno%20della%20settimana%20dal%20campo%20datetime%20(scripting)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-215228%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ECiao%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHo%20un%20campo%20START_TIME%20(formato%20datetime)%2C%20ad%20es%3C%2FP%3E%3CP%3E15.06.2019%206%3A05%3C%2FP%3E%3CP%3E16.06.2019%208%3A12%3C%2FP%3E%3CP%3E17.06.2019%207%3A01%20ecc.%3C%2FP%3E%3CP%3EVorrei%20mantenere%20tutti%20i%20giorni%20che%20sono%20il%20sabato%20e%20la%20domenica.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EImmagino%2C%20estraendo%2C%20riceverei%20un%20valore%20come%3C%2FP%3E%3CP%3ESTART_TIME%20SAT_SUN%3C%2FP%3E%3CP%3E15.06.2019%206%3A05%207%3C%2FP%3E%3CP%3E16.06.2019%208%3A12%201%3C%2FP%3E%3CP%3E17.06.2019%207%3A01%202%3C%2FP%3E%3CP%3EQuindi%20uso%20solo%20mantenere%201s%20e%207s%2C%20giusto.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECome%20potrei%20farlo%20con%20lo%20script%20JSL%3F%3C%2FP%3E%3CP%3EHo%20provato%20approcci%20come%3C%2FP%3E%3CP%3Edt%20%26lt%3B%26lt%3B%20Nuova%20colonna%20(%22SAT_SUN%22%2C%20numerico%2C%20formato%20(giorno%20della%20settimana%20(%3A%20START_TIME)%2C%20%22datetime%22))%3B%3C%2FP%3E%3CP%3Equello%20non%20sembra%20funzionare.%3C%2FP%3E%3CP%3EQualche%20idea%3F%3C%2FP%3E%3CP%3ESaluti!%3C%2FP%3E%3CP%3ENovizio%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-215261%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERi%3A%20JSL%3A%20Estrai%20giorno%20della%20settimana%20dal%20campo%20datetime%20(scripting)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-215261%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ESemplice%20idea%20(visto%20che%20devo%20lasciare%20un%20minuto)%3A%20se%20vuoi%20mantenere%20tutti%20i%20valori%20puoi%20semplicemente%20usare%20il%20comando%20filtro%20ed%20escludere%20tutti%20gli%20altri%20che%20non%20corrispondono%20a%20SAT%20%2F%20SUN.%20%3CBR%20%2F%3ESe%20vuoi%20davvero%20rimuovere%20le%20righe%20non%20uguali%20a%20SAT%20%2F%20SUN%2C%20usa%20SELECT%20WHERE%20e%20poi%20elimina%20le%20righe.%20Qualcuno%20pu%C3%B2%20scrivere%20uno%20script%20demo%20%3A)%3C%2Fimg%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-215280%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERi%3A%20JSL%3A%20Estrai%20giorno%20della%20settimana%20dal%20campo%20datetime%20(scripting)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-215280%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ENon%20%C3%A8%20necessario%20creare%20una%20nuova%20colonna%20per%20fare%20ci%C3%B2%20che%20vuoi.%26nbsp%3B%20Ecco%20un%20semplice%20script%20che%20fa%20ci%C3%B2%20che%20hai%20chiesto%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0Adt%20%3D%20Open(%20%22%24SAMPLE_DATA%2FAircraft%20Incidents.jmp%22%20)%3B%0A%0Adt%20%26lt%3B%26lt%3B%20select%20where(%20Day%20Of%20Week(%20%3AEvent%20Date%20)%20%3D%3D%201%20%7C%20Day%20Of%20Week(%20%3AEvent%20Date%20)%20%3D%3D%207%20)%3B%0A%0Adtsub%20%3D%20dt%20%26lt%3B%26lt%3B%20subset(%20selected%20rows(%201%20)%2C%20selected%20columns(%200%20)%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-215283%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERi%3A%20JSL%3A%20Estrai%20giorno%20della%20settimana%20dal%20campo%20datetime%20(scripting)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-215283%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ESe%20necessario%2C%20usa%20%22Aiuto%26gt%3B%20Indice%20di%20scripting%22%20per%20trovare%20maggiori%20dettagli%20su%20come%20funzionano%20i%20comandi%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENamesDefaultToHere(1)%3B%0A%0A%2F%2F%20Make%20a%20table%20of%20random%20dates%0An%20%3D%2050%3B%0AstartDate%20%3D%20Date%20DMY(%2001%2C%201%2C%202016%20)%3B%0AendDate%20%3D%20Date%20DMY(%2012%2C%2010%2C%202016%20)%3B%0Adates%20%3D%20Sort%20Ascending(%20J(%20n%2C%201%2C%20Random%20Integer(startDate%2C%20endDate)%20)%20)%3B%0Adt%20%3D%20New%20Table(%20%22Dates%22%2C%0A%20%20%20New%20Column(%20%22Random%20dates%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%20%22ddMonyyyy%20h%3Am%22%2C%2035%20)%2C%20Set%20Values(%20dates%20))%2C%0A%20%20)%3B%0A%0A%2F%2F%20Add%20a%20formula%20for%20the%20day%20of%20the%20week%0Anc%20%3D%20dt%20%26lt%3B%26lt%3B%20New%20Column(%20%22Day%20of%20the%20week%22%2C%0A%20%20%20%20%20%20Numeric%2C%0A%20%20%20%20%20%20%22Continuous%22%2C%0A%20%20%20%20%20%20Format(%20%22Best%22%2C%2012%20)%2C%0A%20%20%20%20%20%20Formula(%20Day%20Of%20Week(%20%3ARandom%20dates%20)%20)%2C%0A%20%20%20%20%20%20Value%20Labels(%0A%20%20%20%20%20%20%20%7B1%20%3D%20%22Sunday%22%2C%202%20%3D%20%22Monday%22%2C%203%20%3D%20%22Tuesday%22%2C%204%20%3D%20%22Wednesday%22%2C%205%20%3D%20%22Thursday%22%2C%0A%20%20%20%20%20%20%206%20%3D%20%22Friday%22%2C%207%20%3D%20%22Saturday%22%7D%0A%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20Use%20Value%20Labels(%201%20)%2C%0A%20%20%20%20%20)%3B%0A%0A%2F%2F%20Make%20a%20subset%20table%0Ar%20%3D%20dt%20%26lt%3B%26lt%3B%20getRowsWhere(%3ADay%20of%20the%20week%20%3D%3D%207%20%7C%20%3ADay%20of%20the%20week%20%3D%3D%201)%3B%0Adt2%20%3D%20dt%20%26lt%3B%26lt%3B%20Subset(rows(r)%2C%20LinkToOriginalDataTable(1))%3B%0Adt2%20%26lt%3B%26lt%3B%20setName(%22Weekend%20Dates%22)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
Newbie2Jumpie
Level IV

JSL: Extract day of week from datetime field (scripting)

Hi

 

I have a field START_TIME (datetime format), e.g.

15.06.2019 6:05

16.06.2019 8:12

17.06.2019 7:01 etc.

I would like to keep all days that are Saturdays and Sundays.

 

I imagine, by extracting I would receive a value like

START_TIME         SAT_SUN

15.06.2019 6:05             7

16.06.2019 8:12             1

17.06.2019 7:01             2

Then I just use keep 1s and 7s, right.

 

How would I do that with JSL script?

I tried approaches like

dt << New Column ("SAT_SUN",numeric,format(day of week(:START_TIME),"datetime")) ;

that don't seem to work.

Any idea?

Cheers!

Newbie

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: JSL: Extract day of week from datetime field (scripting)

There is no need to create a new column to do what you want.  Here is a simple script that does what you asked for:

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Aircraft Incidents.jmp" );

dt << select where( Day Of Week( :Event Date ) == 1 | Day Of Week( :Event Date ) == 7 );

dtsub = dt << subset( selected rows( 1 ), selected columns( 0 ) );
Jim

View solution in original post

3 REPLIES 3

Re: JSL: Extract day of week from datetime field (scripting)

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.
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 :)
/****NeverStopLearning****/
ian_jmp
Level X

Re: JSL: Extract day of week from datetime field (scripting)

If needed, use 'Help > Scripting Index' to find more details of how the commands work;

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 << 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 << getRowsWhere(:Day of the week == 7 | :Day of the week == 1);
dt2 = dt << Subset(rows(r), LinkToOriginalDataTable(1));
dt2 << setName("Weekend Dates");

 

txnelson
Super User

Re: JSL: Extract day of week from datetime field (scripting)

There is no need to create a new column to do what you want.  Here is a simple script that does what you asked for:

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Aircraft Incidents.jmp" );

dt << select where( Day Of Week( :Event Date ) == 1 | Day Of Week( :Event Date ) == 7 );

dtsub = dt << subset( selected rows( 1 ), selected columns( 0 ) );
Jim

Recommended Articles