Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
substr()
Syntax
substr(string,position[, length])
Usage
substr returns the characters in string, starting at position position. If you specify length, this function returns length number of characters. If any of the parameters are null, then the function returns null. length is optional.
The first character in string is at position 1. If position is negative then the position is relative to the end of the string. So a position of -1 denotes the last character.
If length is negative, then the function returns null. If position > len (string) or position < -len(string) or position = 0, then the empty string is returned.
Example
1-- we want a substring that is one character long, starting at position 1.
2-- The character "C" is returned.
3substr("CRM", 1, 1)
4
5-- we want a substring that is 2 characters long, starting at position 1
6-- The string "CR" is returned
7substr("CRM", 1, 2) == "CR"
8
9-- we want a substring that is two characters long, starting from the *end* of the string
10-- The string "RM" is returned
11substr("CRM", -2, 2) == "RM"
12
13-- we want to get the first 10 characters from this string
14-- the string "2018-03-16" is returned
15substr("2018-03-16T00:00:03.000Z",10)Example
1q = foreach q generate substr(date_to_string(now(), "yyyy-MM-dd HH:mm:ss"), -11) as 'Time Now';