cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
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

Recommended Articles