Hi @Herrera5238,
Substr() is a really useful character function that can pick out part of a string. The arguments of Substr() are shown in Help > Scripting Index:
Substr(string, start, length)
So, the 1 and 3 in the example tell Substr() to take the string and return 3 characters starting at the 1st ordinal position of the string.The reason this works is that the rest of the formula I wrote
Format( :Date Time, "Monddyyyy" )
returns a formatted version of the date based on the format specified ("Monddyyyy"). If you were to use just that function without Substr() you would get rows with values like: "Jan012018" .
If you would like a non-abbreviated month you would need to do something different. We could start with:
Format( :Date Time, "Date Long" )
which would return something like: Monday, January 1, 2018. Since Substr() requires that we specify a specific starting position and number of characters, it won't be very useful to pick apart this string since the days of the week are different numbers of characters. But, we have many other character functions at our disposal! Word() is a great one -- this will return a particular word in a string based on some delimiter (default is a space, but could also be a comma, or both a comma AND space, which is what we need). Knowing this, we could use the following formula:
Word( 2, Format( :Date Time, "Date Long" ), ", " )
The way to read this is: take the second word (that's the 2) from the formatted date time column (using Date Long), and use as the delimiter of the words BOTH a comma, and a space (notice in quotes I have a comma and then a space--that's how I tell JMP to use both). This will return "January" for the first row in your data set.
But, maybe you also want the year at the end, or beginning, or some intervening characters. We can do all of that using the Concatenating operator ||, or function Concat(). For example, say we want to put the year on the end of the string for each row. We need to get the year somehow (could be the Year() function pointing to :Date Time, or we could use Words() again, both would work). Here's one way to do this:
Word( 2, Format( :Date Time, "Date Long" ), ", " ) || "-" ||
Char( Year( :Date Time ) )
which will return "January-2018." There is one thing I did here that you might not expect. I wrapped Year( :Date Time ) in the Char() function. This is important because Year( :Date Time ) will return a NUMERIC value of the year, and the Concat() function (or its inline operator version ||) requires character arguments. So, adding a simple Char() around Year() makes sure that Concat() is getting a character representation of the year to work with.
There is so much you can do with character functions, and I encourage you to check out the Character section of the formula reference in Help > Scripting Index.
I hope this helps!
@julian