For the latest version of JMP Help, visit JMP.com/help.


Scripting Guide > Types of Data > Date-Time Functions and Formats > Custom Date-Time Formatting with Format Patterns
Publication date: 11/10/2021

Custom Date-Time Formatting with Format Patterns

Format patterns are strings that define a date-time format. Here’s one example:

<YYYY></><MM></><DD> <hh><:><mm><:><ss><ampm>

The parts of the pattern in angle brackets are called field descriptors. They represent a value (such as <YYYY>, which is a four-digit year) or other date-time text (such as </>, which is a locale-specific date separator).

The conversion of a date-time value to a string and a string converted to a date-time value work as follows:

When a date-time value is converted to a string, the field descriptors are replaced by the appropriate value or symbols.

When a string is converted to a date-time value, a value is or matching symbols are expected to be found where each field descriptor is. Anything outside a format descriptor is treated as literal text. The literal text is replaced as-is when it is converted to a string, and is expected to be found where specified when converting from a string.

Table 6.5 Output for Custom Date-Time Formats

Format

Output

<YYYY></><MM></><DD> <hh><:><mm><:><ss><ampm>

2020/02/10 11:54:33 AM

<DayOfWeek>, <Month> <D>, <YYYY>

Wednesday, February 5, 2020

<Day>d <hh24>h <mm>m <ss>s

123d 02h 34m 56s

Note: <Day> is the day count, used as the most significant field of a duration. <Hour> and <Minute> field descriptors are also available.

Example of Outputting the Date-Time Value to the Log

The following script uses Informat() to read a string date-time value, defines the format pattern used in that string, and returns the date in ddMonyyyy format. The script then outputs the date-time value to the log.

dateVal = Informat( "June 16, 2016", "Format Pattern", "<Month> <D>, <YYYY>" );

16Jun2016

Here’s another way to specify the format pattern:

date2 = 16Jun2021;
 
	dayofwk2 = Format( date2, "Format Pattern", "<DayOfWeek>" );
	monthnew2 = Format( date2, "Format Pattern", "<Month>" );
 
	YYYYMMDD = Format( date2, "Format Pattern", "<YYYY></><MM></><DD>" );
	YYMMMDD = Format( date2, "Format Pattern", "<YY></><MMM></><DD>" );

"21/Jun/16"

Example of Changing the Input Format of a Column

The following script shows how to change the input format of a column. The Input Format appears when you edit the value in a data table.

New Table( "temp_date",
	Add Rows( 2 ),
	New Column( "date1",
		Numeric,
		"Continuous",

// specify how the value appears in the data table

		Format( "Format Pattern", "<Month> <D>, <YYYY>", 35 ),

// specify how the value appears when you edit the value

		Input Format( "Format Pattern", "<YYYY>*<MM>*<DD>" ),
		Set Values( {"2018*10*31", "2018*09*09"} )
	),
	New Column( "date2",
		Numeric,
		"Continuous",
		Format( "Format Pattern", "<YYYY>*<MM>*<DD>", 10 ),
		Set Values( {"2018*02*05", "2018*07*03"} )
	)
);

Note: See Customize Date-Time Formats with Format Patterns in Using JMP for details about creating a format pattern in a data table rather than in a script.

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).