I find that the “format” inspector can make for easier conversion of date/time fields into other formats. The format inspector substitutes parameters into a string. I rarely see ‘format’ used outside of some dashboard javascript but I think it could be useful in a lot of cases, for example in formatting dates and times.
https://developer.bigfix.com/relevance/reference/format.html
The ‘format’ inspector starts with a string, and substitutes in positional tags such as {0}, {1}, etc. with parameters specified after the string. Parameters are separated by the + character.
Example:
Q: format "At {1}, user {0} is logged on." + name of current user + now
A: At 9/27/2010 3:03:26 PM, user Scott is logged on.
This can be useful in formatting time and dates:
q: (format "{0}{1}{2}{3}{4}{5}" + year of item 1 of it as string + month of item 1 of it as two digits as string + day_of_month of item 1 of it as two digits as string + two digit hour of item 0 of it + two digit minute of item 0 of it + two digit second of item 0 of it) of (time (universal time zone) of it, date (universal time zone) of it) of now
A: 20200220000618
T: 0.194 ms
I: singular format
Want to change the way it’s presented? Pretty easy, only the part inside the “format” string needs to be modified; the rest of the relevance is unchanged.
q: (format "{0}-{1}-{2}, {3}:{4}:{5}" + year of item 1 of it as string + month of item 1 of it as two digits as string + day_of_month of item 1 of it as two digits as string + two digit hour of item 0 of it + two digit minute of item 0 of it + two digit second of item 0 of it) of (time (universal time zone) of it, date (universal time zone) of it) of now
A: 2020-02-20, 00:12:40
T: 0.220 ms
I: singular format
Change the order to put the time before date? Again, only the order inside the format string changes…the rest of the relevance is untouched
q: (format "{3}:{4}:{5} {0}-{1}-{2}" + year of item 1 of it as string + month of item 1 of it as two digits as string + day_of_month of item 1 of it as two digits as string + two digit hour of item 0 of it + two digit minute of item 0 of it + two digit second of item 0 of it) of (time (universal time zone) of it, date (universal time zone) of it) of now
A: 00:13:37 2020-02-20
T: 0.206 ms
I: singular format
Which, if I understand the history, is exactly why the format inspector was added - for easier localization of strings such as date/time representations and currencies.
Related: