cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
HarriBradbeer
Level II

Change date format in a script

I have a script that requires the user to input a batch creation time. It currently looks like this:

 

 

New Window( "BATCH_CREATE_TIME",
	<<modal(),
	Panel Box( "Enter BATCH_CREATE_TIME",
		Lineup Box( N Col( 1 ) ),
		number = Text Edit Box( "01/01/2021 09:00:00.000000" )
	),
	Panel Box( "Actions",
		H List Box(
			Button Box( "OK",
				keep_going = 1;
				BATCH_TIME = number << Get text;
			),
			Button Box( "Cancel", keep_going = 0 )
		), 

	), 
);

I want to update this so that it automatically puts the current time into the text box, so far I have this:

 

 

CurrTime = As Date(Today()); 

New Window( "BATCH_CREATE_TIME",
	<<modal(),
	Panel Box( "Enter BATCH_CREATE_TIME",
		Lineup Box( N Col( 1 ) ),
		number = Text Edit Box( CurrTime )
	),
	Panel Box( "Actions",
		H List Box(
			Button Box( "OK",
				keep_going = 1;
				BATCH_TIME = number << Get text;
			),
			Button Box( "Cancel", keep_going = 0 )
		), 

	), 
);

Now all I want to do is change the output to match the original format. I currently get the format "01Jan2021:09:00:00". Ideally, I'd like this to be "01/01/2021 09:00:00.000000" (the decimal seconds aren't vital).

 

Any ways that I can change the format of the As Date function?

 

Thanks all.

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Change date format in a script

Your input field is a text box, so you need to convert the date from a numeric number of seconds, to a string using a format() function

CurrTime = format(As Date(Today()),"m/d/y h:m:s",6) ; 

New Window( "BATCH_CREATE_TIME",
	<<modal(),
	Panel Box( "Enter BATCH_CREATE_TIME",
		Lineup Box( N Col( 1 ) ),
		number = Text Edit Box( CurrTime )
	),
	Panel Box( "Actions",
		H List Box(
			Button Box( "OK",
				keep_going = 1;
				BATCH_TIME = number << Get text;
			),
			Button Box( "Cancel", keep_going = 0 )
		), 

	), 
);
Jim

View solution in original post

1 REPLY 1
txnelson
Super User

Re: Change date format in a script

Your input field is a text box, so you need to convert the date from a numeric number of seconds, to a string using a format() function

CurrTime = format(As Date(Today()),"m/d/y h:m:s",6) ; 

New Window( "BATCH_CREATE_TIME",
	<<modal(),
	Panel Box( "Enter BATCH_CREATE_TIME",
		Lineup Box( N Col( 1 ) ),
		number = Text Edit Box( CurrTime )
	),
	Panel Box( "Actions",
		H List Box(
			Button Box( "OK",
				keep_going = 1;
				BATCH_TIME = number << Get text;
			),
			Button Box( "Cancel", keep_going = 0 )
		), 

	), 
);
Jim