Format

This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics.

Format( "format", arg, ... )
Format( "format", Arr(arg, ...) )
Format( "format", arg, ... )
Format( "format", Arr(arg, ...) )
Format( 'format', arg, ... )
Format( 'format', [ arg, ... ] )
format( "format", arg, ... )
format( "format", [ arg, ... ] )
Format( 'format', arg, ... )
Format( 'format', [ arg, ... ] )

Description

The Format function applies the format argument to compose a string by converting the remaining arguments to strings. Format is very similar to the printf() function that is available in many languages.

The format argument is a string that includes format specifiers that define how arguments should be converted to strings.

format should contain as many format specifiers as there are remaining arguments. format can include fewer format specifiers than remaining arguments, but an errors occurs when more format specifiers are included than remaining arguments.

If an argument cannot be formatted according to format, an error is returned.

Parameters

Parameter Type Definition and Requirements

format

String

The format to apply to following arguments. See the Format section for details.

arguments

Array, or list of arguments.

The arguments to format.

Returns

A string value representing the formatted arguments, or an error if any format conversion fails.

Format

The format parameter is a string that contains format specifiers. Each format specifier defines how a function argument is to be converted into a string. Format specifiers use the following syntax:

%[index$][flags][width][.precision]conversion[suffix]
  • The optional index specification is a positive decimal integer (>= 1) that indicates the relative position of the argument to format from the argument list, followed by a dollar sign ($) — to separate the index from the optional flags.

    format, as the first function argument, has a zero offset in the argument list. The next argument has an offset of 1, followed by 2, and so on.

  • The optional flags specification is a set of characters that modify the output format. The set of valid flags depends on the conversion. See Flags for details.

  • The optional width specification is a positive decimal integer indicating the minimum number of characters to be included in the output for this conversion.

  • The optional precision specification is a non-negative decimal integer that is usually used to restrict the number of characters produced for this conversion. The specific behavior depends on the conversion.

  • The required conversion specification is a character that indicates how the associated argument is to be formatted when it is converted to a string. The set of valid conversions for a given argument depends on the argument’s data type. See Conversions for details.

  • The optional suffix specification is a character that indicates which time or date field to use for timestamp conversions. See Suffixes for dates, Suffixes for times, or Suffixes for dates and times for details.

Flags

Flag Description

-

The result is left-justified.

+

The result always includes a sign, positive or negative.

 (space)

The result includes a leading space for positive values.

0

The result is zero padded.

(

The result encloses negative numbers in parentheses.

Conversions

Conversion Description

%d

The result is formatted as a decimal integer.

%x

The result is formatted as a hexadecimal integer.

%X

The result is formatted as a hexadecimal integer. All letters are converted to uppercase.

%o

The result is formatted as an octal integer.

%f

The result is formatted as a decimal number.

%e

The result is formatted as a number using scientific notation.

%E

The result is formatted as a number using scientific notation. All letters are converted to uppercase.

%g

The result is formatted as a number using scientific notation, or a decimal number, depending on the precision.

%G

The result is formatted as a number using scientific notation, or a decimal number, depending on the precision. All letters are converted to uppercase.

%s

The result is formatted as string. If the argument is null, the "null" string is returned.

%S

The result is formatted as string. If the argument is null, the "null" string should be returned. All letters are converted to uppercase.

%t

The result is formatted as Date/Time in ISO-8601 format. An optional suffix can be included to select a specific date or time field for formatting.

%b

The result is formatted as boolean.

%B

The result is formatted as boolean. All letters are converted to uppercase.

%%

The literal character % (percent sign).

%n

The system-specific line break.

%@

The result is formatted as the Fauna wire protocol. (This is a debug conversion which applies to all non-scalar values)

Suffixes for dates

The following are suffixes for the %t conversion that are used to format specific date fields:

Suffix Description

B

The full month name, e.g. January.

b

The abbreviated month name, e.g. Jan.

h

The same as the b suffix.

A

The full name of the day of the week, e.g. Monday.

a

The abbreviated name of the day of the week, e.g. Mon.

C

The year divided by 100 (the century), formatted as 2 digits with leading zeroes as necessary, e.g. 00-99.

Y

The year, formatted as 4 digits with leading zeroes as necessary, in the range 0000-9999.

y

The last two digits of the year, formatted with leading zeroes as necessary, in the range 00-99.

j

The day of the year, formatted as 3 digits with leading zeroes as necessary, in the range 001-366.

m

The month, formatted as 2 digits with a leading zero as necessary, in the range 01-13 (13 is required for lunar calendars).

d

The day of the month, formatted as 2 digits with a leading zero as necessary, in the range 01-31.

e

The day of month, formatted as 2 characters with a leading space as necessary, in the range 1-31.

D

The date, formatted as %tm/%td/%ty, e.g. 08/16/2019.

F

The date formatted as %tY-%tm-%td, e.g. 2019-08-16.

Suffixes for times

The following are suffixes for the %t conversion that are used to format specific time fields:

Suffix Description

H

The hour, formatted as 2 digits with leading zeroes as necessary, in the range 00-23.

I

The hour, formatted as 2 digits with a leading zero as necessary, in the range 01-12.

k

The hour, formatted as 1 or 2 digits, in the range 0-23.

l

The hour, formatted as 1 or 2 digits, in the range 1-12.

M

The minute, formatted as 2 digits with leading zeroes as necessary, in the range 00-59.

S

The second, formatted as 2 digits with leading zeroes as necessary, in the range 00-60.

L

The millisecond within the second, formatted as 3 digits with leading zeroes as necessary, in the range 000-999.

N

The nanosecond within the second, formatted as 9 digits with leading zeroes as necessary, in the range 000000000-999999999.

p

The morning or afternoon marker, am or pm (AM or PM with the T conversion).

s

The seconds since epoch (1970-01-01T00:00:00+00:00).

Q

The milliseconds since epoch (1970-01-01T00:00:00.000+00:00).

Suffixes for dates and times

The following are suffixes for the %t conversion that are used to format common date+time compositions:

Suffix Description

R

The time as %tH:%tM, e.g. 18:51.

T

The time as %tH:%tM:%tS, e.g. 18:51:33.

r

The time as %tI:%tM:%tS %Tp, e.g. 06:51:33 PM.

D

The date as %tm/%td/%ty, e.g. 08/16/19.

F

The date as %tY-%tm-%td, e.g. 2019-08-16.

c

The date and time as %ta %tb %td %tT %tZ %tY, e.g. Fri Aug 16 18:51:33 Z 2019.

Examples

try
{
    Value result = await client.Query(
        Let(
            "ts", Time("2019-08-16T18:51:33.987654321+00:00")
        ).In(
            Concat(
                Arr(
                    Format("%nDecimals:"),
                    Repeat("-=", 30),
                    Format("                   normal: '%d'", 123),
                    Format("                with sign: '%+d'", 123),
                    Format("               with width: '%7d'", 123),
                    Format("   with width, align left: '%-7d'", 123),
                    Format("           as hexadecimal: '%x'", 123),
                    Format("as hexadecimal, uppercase: '%X'", 123),
                    Format("                 as octal: '%o'", 123),

                    Format("%nFloats:"),
                    Repeat("=-", 30),
                    Format("                         normal: '%f'", 123.456789),
                    Format("                     2 decimals: '%.2f'", 123.456789),
                    Format("            scientific notation: '%e'", 123.456789),
                    Format("scientific notation, 2 decimals: '%.2e'", 123.456789),
                    Format(" scientific notation, uppercase: '%E'", 123.456789),
                    Format("                             %%g: '%g'", 123.456789),
                    Format("                 %%g, 2 decimals: '%.2g'", 123.456789),
                    Format("                             %%G: '%g'", 123.456789),
                    Format("                 %%G, 2 decimals: '%.2g'", 123.456789),

                    Format("%nStrings:"),
                    Repeat("-=", 30),
                    Format("   normal: '%s'", "Fauna"),
                    Format("uppercase: '%S'", "Fauna"),
                    Format("     null: '%s'", null),
                    Format("       %%%%: '%%'"),
                    Format("linefeed: %n"),

                    Format("%nBooleans:"),
                    Repeat("=-", 30),
                    Format("            true: '%b'", true),
                    Format(" true, uppercase: '%B'", 1),
                    Format("           false: '%b'", false),
                    Format("false, uppercase: '%B'", 0),

                    Format("%nTimes and Dates:"),
                    Repeat("-=", 30),
                    Format("                    ISO-8601: %t", Var("ts")),
                    Format("         ISO-8601, uppercase: %T", Var("ts")),
                    Format(""),
                    Format("             Full month name: %tB", Var("ts")),
                    Format("  Full month name, uppercase: %TB", Var("ts")),
                    Format("            Short month name: %tb", Var("ts")),
                    Format(" Short month name, uppercase: %Tb", Var("ts")),
                    Format("                          %%h: %th", Var("ts")),
                    Format("               %%h, uppercase: %Tb", Var("ts")),
                    Format("                Full weekday: %tA", Var("ts")),
                    Format("     Full weekday, uppercase: %TA", Var("ts")),
                    Format("               Short weekday: %ta", Var("ts")),
                    Format("    Short weekday, uppercase: %Ta", Var("ts")),
                    Format("                     Century: %tC", Var("ts")),
                    Format("                        Year: %tY", Var("ts")),
                    Format("                  Short year: %ty", Var("ts")),
                    Format("             Day of the year: %tj", Var("ts")),
                    Format("                       Month: %tm", Var("ts")),
                    Format("            Day of the month: %td", Var("ts")),
                    Format(""),

                    Format("      Hour, leading 0's (24): %tH", Var("ts")),
                    Format("      Hour, leading 0's (12): %tI", Var("ts")),
                    Format("                   Hour (24): %tk", Var("ts")),
                    Format("                   Hour (12): %tl", Var("ts")),
                    Format("                      Minute: %tM", Var("ts")),
                    Format("                      Second: %tS", Var("ts")),
                    Format("                 Millisecond: %tL", Var("ts")),
                    Format("                  Nanosecond: %tN", Var("ts")),
                    Format("           Morning/afternoon: %tp", Var("ts")),
                    Format("Morning/afternoon, uppercase: %Tp", Var("ts")),
                    Format("         Seconds since epoch: %ts", Var("ts")),
                    Format("    Milliseconds since epoch: %tQ", Var("ts")),
                    Format(""),

                    Format("                          %%R: %tR", Var("ts")),
                    Format("                          %%T: %tT", Var("ts")),
                    Format("                          %%r: %tr", Var("ts")),
                    Format("                          %%D: %tD", Var("ts")),
                    Format("                          %%F: %tF", Var("ts")),
                    Format("                          %%c: %tc", Var("ts")),
                    Format("")
                ),
                "\n"
            )
        )
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
StringV(
Decimals:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                   normal: '123'
                with sign: '+123'
               with width: '    123'
   with width, align left: '123    '
           as hexadecimal: '7b'
as hexadecimal, uppercase: '7B'
                 as octal: '173'

Floats:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                         normal: '123.456789'
                     2 decimals: '123.46'
            scientific notation: '1.234568e+02'
scientific notation, 2 decimals: '1.23e+02'
 scientific notation, uppercase: '1.234568E+02'
                             %g: '123.457'
                 %g, 2 decimals: '1.2e+02'
                             %G: '123.457'
                 %G, 2 decimals: '1.2e+02'

Strings:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
   normal: 'Fauna'
uppercase: 'FAUNA'
     null: 'null'
       %%: '%'
linefeed: 


Booleans:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
            true: 'true'
 true, uppercase: 'TRUE'
           false: 'false'
false, uppercase: 'TRUE'

Times and Dates:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                    ISO-8601: 2019-08-16T18:51:33.987654321Z
         ISO-8601, uppercase: 2019-08-16T18:51:33.987654321Z

             Full month name: August
  Full month name, uppercase: AUGUST
            Short month name: Aug
 Short month name, uppercase: AUG
                          %h: Aug
               %h, uppercase: AUG
                Full weekday: Friday
     Full weekday, uppercase: FRIDAY
               Short weekday: Fri
    Short weekday, uppercase: FRI
                     Century: 20
                        Year: 2019
                  Short year: 19
             Day of the year: 228
                       Month: 08
            Day of the month: 16

      Hour, leading 0's (24): 18
      Hour, leading 0's (12): 06
                   Hour (24): 18
                   Hour (12): 6
                      Minute: 51
                      Second: 33
                 Millisecond: 987
                  Nanosecond: 987654321
           Morning/afternoon: pm
Morning/afternoon, uppercase: PM
         Seconds since epoch: 1565981493
    Milliseconds since epoch: 1565981493987

                          %R: 18:51
                          %T: 18:51:33
                          %r: 06:51:33 PM
                          %D: 08/16/19
                          %F: 2019-08-16
                          %c: Fri Aug 16 18:51:33 Z 2019
)
result, err := client.Query(
	f.Let().Bind("ts", f.Time("2019-08-16T18:51:33.987654321+00:00")).In(
		f.Concat(
			f.Arr{
				f.Format("%nDecimals:"),
				f.Repeat("-=", f.Number(30)),
				f.Format("                   normal: '%d'", 123),
				f.Format("                with sign: '%+d'", 123),
				f.Format("               with width: '%7d'", 123),
				f.Format("   with width, align left: '%-7d'", 123),
				f.Format("           as hexadecimal: '%x'", 123),
				f.Format("as hexadecimal, uppercase: '%X'", 123),
				f.Format("                 as octal: '%o'", 123),

				f.Format("%nFloats:"),
				f.Repeat("=-", f.Number(30)),
				f.Format("                         normal: '%f'", 123.456789),
				f.Format("                     2 decimals: '%.2f'", 123.456789),
				f.Format("            scientific notation: '%e'", 123.456789),
				f.Format("scientific notation, 2 decimals: '%.2e'", 123.456789),
				f.Format(" scientific notation, uppercase: '%E'", 123.456789),
				f.Format("                             %%g: '%g'", 123.456789),
				f.Format("                 %%g, 2 decimals: '%.2g'", 123.456789),
				f.Format("                             %%G: '%g'", 123.456789),
				f.Format("                 %%G, 2 decimals: '%.2g'", 123.456789),

				f.Format("%nStrings:"),
				f.Repeat("-=", f.Number(30)),
				f.Format("   normal: '%s'", "Fauna"),
				f.Format("uppercase: '%S'", "Fauna"),
				f.Format("     null: '%s'", nil),
				f.Format("       %%%%: '%%'"),
				f.Format("linefeed: %n"),

				f.Format("%nBooleans:"),
				f.Repeat("=-", f.Number(30)),
				f.Format("            true: '%b'", true),
				f.Format(" true, uppercase: '%B'", 1),
				f.Format("           false: '%b'", false),
				f.Format("false, uppercase: '%B'", 0),

				f.Format("%nTimes and Dates:"),
				f.Repeat("-=", f.Number(30)),
				f.Format("                    ISO-8601: %t", f.Var("ts")),
				f.Format("         ISO-8601, uppercase: %T", f.Var("ts")),
				f.Format(""),
				f.Format("             Full month name: %tB", f.Var("ts")),
				f.Format("  Full month name, uppercase: %TB", f.Var("ts")),
				f.Format("            Short month name: %tb", f.Var("ts")),
				f.Format(" Short month name, uppercase: %Tb", f.Var("ts")),
				f.Format("                          %%h: %th", f.Var("ts")),
				f.Format("               %%h, uppercase: %Tb", f.Var("ts")),
				f.Format("                Full weekday: %tA", f.Var("ts")),
				f.Format("     Full weekday, uppercase: %TA", f.Var("ts")),
				f.Format("               Short weekday: %ta", f.Var("ts")),
				f.Format("    Short weekday, uppercase: %Ta", f.Var("ts")),
				f.Format("                     Century: %tC", f.Var("ts")),
				f.Format("                        Year: %tY", f.Var("ts")),
				f.Format("                  Short year: %ty", f.Var("ts")),
				f.Format("             Day of the year: %tj", f.Var("ts")),
				f.Format("                       Month: %tm", f.Var("ts")),
				f.Format("            Day of the month: %td", f.Var("ts")),
				f.Format(""),

				f.Format("      Hour, leading 0's (24): %tH", f.Var("ts")),
				f.Format("      Hour, leading 0's (12): %tI", f.Var("ts")),
				f.Format("                   Hour (24): %tk", f.Var("ts")),
				f.Format("                   Hour (12): %tl", f.Var("ts")),
				f.Format("                      Minute: %tM", f.Var("ts")),
				f.Format("                      Second: %tS", f.Var("ts")),
				f.Format("                 Millisecond: %tL", f.Var("ts")),
				f.Format("                  Nanosecond: %tN", f.Var("ts")),
				f.Format("           Morning/afternoon: %tp", f.Var("ts")),
				f.Format("Morning/afternoon, uppercase: %Tp", f.Var("ts")),
				f.Format("         Seconds since epoch: %ts", f.Var("ts")),
				f.Format("    Milliseconds since epoch: %tQ", f.Var("ts")),
				f.Format(""),

				f.Format("                          %%R: %tR", f.Var("ts")),
				f.Format("                          %%T: %tT", f.Var("ts")),
				f.Format("                          %%r: %tr", f.Var("ts")),
				f.Format("                          %%D: %tD", f.Var("ts")),
				f.Format("                          %%F: %tF", f.Var("ts")),
				f.Format("                          %%c: %tc", f.Var("ts")),
				f.Format(""),
			},
			f.Separator("\n"))))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
Decimals:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                   normal: '123'
                with sign: '+123'
               with width: '    123'
   with width, align left: '123    '
           as hexadecimal: '7b'
as hexadecimal, uppercase: '7B'
                 as octal: '173'

Floats:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                         normal: '123.456789'
                     2 decimals: '123.46'
            scientific notation: '1.234568e+02'
scientific notation, 2 decimals: '1.23e+02'
 scientific notation, uppercase: '1.234568E+02'
                             %g: '123.457'
                 %g, 2 decimals: '1.2e+02'
                             %G: '123.457'
                 %G, 2 decimals: '1.2e+02'

Strings:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
   normal: 'Fauna'
uppercase: 'FAUNA'
     null: 'null'
       %%: '%'
linefeed: 


Booleans:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
            true: 'true'
 true, uppercase: 'TRUE'
           false: 'false'
false, uppercase: 'TRUE'

Times and Dates:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                    ISO-8601: 2019-08-16T18:51:33.987654321Z
         ISO-8601, uppercase: 2019-08-16T18:51:33.987654321Z

             Full month name: August
  Full month name, uppercase: AUGUST
            Short month name: Aug
 Short month name, uppercase: AUG
                          %h: Aug
               %h, uppercase: AUG
                Full weekday: Friday
     Full weekday, uppercase: FRIDAY
               Short weekday: Fri
    Short weekday, uppercase: FRI
                     Century: 20
                        Year: 2019
                  Short year: 19
             Day of the year: 228
                       Month: 08
            Day of the month: 16

      Hour, leading 0's (24): 18
      Hour, leading 0's (12): 06
                   Hour (24): 18
                   Hour (12): 6
                      Minute: 51
                      Second: 33
                 Millisecond: 987
                  Nanosecond: 987654321
           Morning/afternoon: pm
Morning/afternoon, uppercase: PM
         Seconds since epoch: 1565981493
    Milliseconds since epoch: 1565981493987

                          %R: 18:51
                          %T: 18:51:33
                          %r: 06:51:33 PM
                          %D: 08/16/19
                          %F: 2019-08-16
                          %c: Fri Aug 16 18:51:33 Z 2019
client.query(
  q.Let(
    { ts: q.Time('2019-08-16T18:51:33.987654321+00:00') },
    q.Concat(
      [
        q.Format('%nDecimals:'),
        q.Repeat('-=', 30),
        q.Format('                   normal: "%d"', 123),
        q.Format('                with sign: "%+d"', 123),
        q.Format('               with width: "%7d"', 123),
        q.Format('   with width, align left: "%-7d"', 123),
        q.Format('           as hexadecimal: "%x"', 123),
        q.Format('as hexadecimal, uppercase: "%X"', 123),
        q.Format('                 as octal: "%o"', 123),

        q.Format('%nFloats:'),
        q.Repeat('=-', 30),
        q.Format('                         normal: "%f"', 123.456789),
        q.Format('                     2 decimals: "%.2f"', 123.456789),
        q.Format('            scientific notation: "%e"', 123.456789),
        q.Format('scientific notation, 2 decimals: "%.2e"', 123.456789),
        q.Format(' scientific notation, uppercase: "%E"', 123.456789),
        q.Format('                             %%g: "%g"', 123.456789),
        q.Format('                 %%g, 2 decimals: "%.2g"', 123.456789),
        q.Format('                             %%G: "%g"', 123.456789),
        q.Format('                 %%G, 2 decimals: "%.2g"', 123.456789),

        q.Format('%nStrings:'),
        q.Repeat('-=', 30),
        q.Format('   normal: "%s"', 'Fauna'),
        q.Format('uppercase: "%S"', 'Fauna'),
        q.Format('     null: "%s"', null),
        q.Format('       %%%%: "%%"'),
        q.Format('linefeed: %n'),

        q.Format('%nBooleans:'),
        q.Repeat('=-', 30),
        q.Format('            true: "%b"', true),
        q.Format(' true, uppercase: "%B"', 1),
        q.Format('           false: "%b"', false),
        q.Format('false, uppercase: "%B"', 0),

        q.Format('%nTimes and Dates:'),
        q.Repeat('-=', 30),
        q.Format('                    ISO-8601: %t', q.Var('ts')),
        q.Format('         ISO-8601, uppercase: %T', q.Var('ts')),
        q.Format(''),
        q.Format('             Full month name: %tB', q.Var('ts')),
        q.Format('  Full month name, uppercase: %TB', q.Var('ts')),
        q.Format('            Short month name: %tb', q.Var('ts')),
        q.Format(' Short month name, uppercase: %Tb', q.Var('ts')),
        q.Format('                          %%h: %th', q.Var('ts')),
        q.Format('               %%h, uppercase: %Tb', q.Var('ts')),
        q.Format('                Full weekday: %tA', q.Var('ts')),
        q.Format('     Full weekday, uppercase: %TA', q.Var('ts')),
        q.Format('               Short weekday: %ta', q.Var('ts')),
        q.Format('    Short weekday, uppercase: %Ta', q.Var('ts')),
        q.Format('                     Century: %tC', q.Var('ts')),
        q.Format('                        Year: %tY', q.Var('ts')),
        q.Format('                  Short year: %ty', q.Var('ts')),
        q.Format('             Day of the year: %tj', q.Var('ts')),
        q.Format('                       Month: %tm', q.Var('ts')),
        q.Format('            Day of the month: %td', q.Var('ts')),
        q.Format(''),

        q.Format('      Hour, leading 0\'s (24): %tH', q.Var('ts')),
        q.Format('      Hour, leading 0\'s (12): %tI', q.Var('ts')),
        q.Format('                   Hour (24): %tk', q.Var('ts')),
        q.Format('                   Hour (12): %tl', q.Var('ts')),
        q.Format('                      Minute: %tM', q.Var('ts')),
        q.Format('                      Second: %tS', q.Var('ts')),
        q.Format('                 Millisecond: %tL', q.Var('ts')),
        q.Format('                  Nanosecond: %tN', q.Var('ts')),
        q.Format('           Morning/afternoon: %tp', q.Var('ts')),
        q.Format('Morning/afternoon, uppercase: %Tp', q.Var('ts')),
        q.Format('         Seconds since epoch: %ts', q.Var('ts')),
        q.Format('    Milliseconds since epoch: %tQ', q.Var('ts')),
        q.Format(''),

        q.Format('                          %%R: %tR', q.Var('ts')),
        q.Format('                          %%T: %tT', q.Var('ts')),
        q.Format('                          %%r: %tr', q.Var('ts')),
        q.Format('                          %%D: %tD', q.Var('ts')),
        q.Format('                          %%F: %tF', q.Var('ts')),
        q.Format('                          %%c: %tc', q.Var('ts')),
        q.Format(''),
      ],
      '\n'
    )
  )
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
Decimals:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                   normal: "123"
                with sign: "+123"
               with width: "    123"
   with width, align left: "123    "
           as hexadecimal: "7b"
as hexadecimal, uppercase: "7B"
                 as octal: "173"

Floats:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                         normal: "123.456789"
                     2 decimals: "123.46"
            scientific notation: "1.234568e+02"
scientific notation, 2 decimals: "1.23e+02"
 scientific notation, uppercase: "1.234568E+02"
                             %g: "123.457"
                 %g, 2 decimals: "1.2e+02"
                             %G: "123.457"
                 %G, 2 decimals: "1.2e+02"

Strings:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
   normal: "Fauna"
uppercase: "FAUNA"
     null: "null"
       %%: "%"
linefeed: 


Booleans:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
            true: "true"
 true, uppercase: "TRUE"
           false: "false"
false, uppercase: "TRUE"

Times and Dates:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                    ISO-8601: 2019-08-16T18:51:33.987654321Z
         ISO-8601, uppercase: 2019-08-16T18:51:33.987654321Z

             Full month name: August
  Full month name, uppercase: AUGUST
            Short month name: Aug
 Short month name, uppercase: AUG
                          %h: Aug
               %h, uppercase: AUG
                Full weekday: Friday
     Full weekday, uppercase: FRIDAY
               Short weekday: Fri
    Short weekday, uppercase: FRI
                     Century: 20
                        Year: 2019
                  Short year: 19
             Day of the year: 228
                       Month: 08
            Day of the month: 16

      Hour, leading 0's (24): 18
      Hour, leading 0's (12): 06
                   Hour (24): 18
                   Hour (12): 6
                      Minute: 51
                      Second: 33
                 Millisecond: 987
                  Nanosecond: 987654321
           Morning/afternoon: pm
Morning/afternoon, uppercase: PM
         Seconds since epoch: 1565981493
    Milliseconds since epoch: 1565981493987

                          %R: 18:51
                          %T: 18:51:33
                          %r: 06:51:33 PM
                          %D: 08/16/19
                          %F: 2019-08-16
                          %c: Fri Aug 16 18:51:33 Z 2019
result = client.query(
  q.let(
    {"ts": q.time("2019-08-16T18:51:33.987654321+00:00")},
    q.concat(
      [
        q.format("%nDecimals:"),
        q.repeat("-=", 30),
        q.format("                   normal: '%d'", 123),
        q.format("                with sign: '%+d'", 123),
        q.format("               with width: '%7d'", 123),
        q.format("   with width, align left: '%-7d'", 123),
        q.format("           as hexadecimal: '%x'", 123),
        q.format("as hexadecimal, uppercase: '%X'", 123),
        q.format("                 as octal: '%o'", 123),

        q.format("%nFloats:"),
        q.repeat("=-", 30),
        q.format("                         normal: '%f'", 123.456789),
        q.format("                     2 decimals: '%.2f'", 123.456789),
        q.format("            scientific notation: '%e'", 123.456789),
        q.format("scientific notation, 2 decimals: '%.2e'", 123.456789),
        q.format(" scientific notation, uppercase: '%E'", 123.456789),
        q.format("                             %%g: '%g'", 123.456789),
        q.format("                 %%g, 2 decimals: '%.2g'", 123.456789),
        q.format("                             %%G: '%g'", 123.456789),
        q.format("                 %%G, 2 decimals: '%.2g'", 123.456789),

        q.format("%nStrings:"),
        q.repeat("-=", 30),
        q.format("   normal: '%s'", "Fauna"),
        q.format("uppercase: '%S'", "Fauna"),
        q.format("     null: '%s'", None),
        q.format("       %%%%: '%%'"),
        q.format("linefeed: %n"),

        q.format("%nBooleans:"),
        q.repeat("=-", 30),
        q.format("            true: '%b'", True),
        q.format(" true, uppercase: '%B'", 1),
        q.format("           false: '%b'", False),
        q.format("false, uppercase: '%B'", 0),

        q.format("%nTimes and Dates:"),
        q.repeat("-=", 30),
        q.format("                    ISO-8601: %t", q.var("ts")),
        q.format("         ISO-8601, uppercase: %T", q.var("ts")),
        q.format(""),
        q.format("             Full month name: %tB", q.var("ts")),
        q.format("  Full month name, uppercase: %TB", q.var("ts")),
        q.format("            Short month name: %tb", q.var("ts")),
        q.format(" Short month name, uppercase: %Tb", q.var("ts")),
        q.format("                          %%h: %th", q.var("ts")),
        q.format("               %%h, uppercase: %Tb", q.var("ts")),
        q.format("                Full weekday: %tA", q.var("ts")),
        q.format("     Full weekday, uppercase: %TA", q.var("ts")),
        q.format("               Short weekday: %ta", q.var("ts")),
        q.format("    Short weekday, uppercase: %Ta", q.var("ts")),
        q.format("                     Century: %tC", q.var("ts")),
        q.format("                        Year: %tY", q.var("ts")),
        q.format("                  Short year: %ty", q.var("ts")),
        q.format("             Day of the year: %tj", q.var("ts")),
        q.format("                       Month: %tm", q.var("ts")),
        q.format("            Day of the month: %td", q.var("ts")),
        q.format(""),

        q.format("      Hour, leading 0's (24): %tH", q.var("ts")),
        q.format("      Hour, leading 0's (12): %tI", q.var("ts")),
        q.format("                   Hour (24): %tk", q.var("ts")),
        q.format("                   Hour (12): %tl", q.var("ts")),
        q.format("                      Minute: %tM", q.var("ts")),
        q.format("                      Second: %tS", q.var("ts")),
        q.format("                 Millisecond: %tL", q.var("ts")),
        q.format("                  Nanosecond: %tN", q.var("ts")),
        q.format("           Morning/afternoon: %tp", q.var("ts")),
        q.format("Morning/afternoon, uppercase: %Tp", q.var("ts")),
        q.format("         Seconds since epoch: %ts", q.var("ts")),
        q.format("    Milliseconds since epoch: %tQ", q.var("ts")),
        q.format(""),

        q.format("                          %%R: %tR", q.var("ts")),
        q.format("                          %%T: %tT", q.var("ts")),
        q.format("                          %%r: %tr", q.var("ts")),
        q.format("                          %%D: %tD", q.var("ts")),
        q.format("                          %%F: %tF", q.var("ts")),
        q.format("                          %%c: %tc", q.var("ts")),
        q.format(""),
      ],
      "\n"
    )
  )
)
print(result)
Decimals:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                   normal: '123'
                with sign: '+123'
               with width: '    123'
   with width, align left: '123    '
           as hexadecimal: '7b'
as hexadecimal, uppercase: '7B'
                 as octal: '173'

Floats:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                         normal: '123.456789'
                     2 decimals: '123.46'
            scientific notation: '1.234568e+02'
scientific notation, 2 decimals: '1.23e+02'
 scientific notation, uppercase: '1.234568E+02'
                             %g: '123.457'
                 %g, 2 decimals: '1.2e+02'
                             %G: '123.457'
                 %G, 2 decimals: '1.2e+02'

Strings:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
   normal: 'Fauna'
uppercase: 'FAUNA'
     null: 'null'
       %%: '%'
linefeed: 


Booleans:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
            true: 'true'
 true, uppercase: 'TRUE'
           false: 'false'
false, uppercase: 'TRUE'

Times and Dates:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                    ISO-8601: 2019-08-16T18:51:33.987654321Z
         ISO-8601, uppercase: 2019-08-16T18:51:33.987654321Z

             Full month name: August
  Full month name, uppercase: AUGUST
            Short month name: Aug
 Short month name, uppercase: AUG
                          %h: Aug
               %h, uppercase: AUG
                Full weekday: Friday
     Full weekday, uppercase: FRIDAY
               Short weekday: Fri
    Short weekday, uppercase: FRI
                     Century: 20
                        Year: 2019
                  Short year: 19
             Day of the year: 228
                       Month: 08
            Day of the month: 16

      Hour, leading 0's (24): 18
      Hour, leading 0's (12): 06
                   Hour (24): 18
                   Hour (12): 6
                      Minute: 51
                      Second: 33
                 Millisecond: 987
                  Nanosecond: 987654321
           Morning/afternoon: pm
Morning/afternoon, uppercase: PM
         Seconds since epoch: 1565981493
    Milliseconds since epoch: 1565981493987

                          %R: 18:51
                          %T: 18:51:33
                          %r: 06:51:33 PM
                          %D: 08/16/19
                          %F: 2019-08-16
                          %c: Fri Aug 16 18:51:33 Z 2019
Let(
  { ts: Time('2019-08-16T18:51:33.987654321+00:00') },
  Concat(
    [
      Format('%nDecimals:'),
      Repeat('-=', 30),
      Format('                   normal: "%d"', 123),
      Format('                with sign: "%+d"', 123),
      Format('               with width: "%7d"', 123),
      Format('   with width, align left: "%-7d"', 123),
      Format('           as hexadecimal: "%x"', 123),
      Format('as hexadecimal, uppercase: "%X"', 123),
      Format('                 as octal: "%o"', 123),

      Format('%nFloats:'),
      Repeat('=-', 30),
      Format('                         normal: "%f"', 123.456789),
      Format('                     2 decimals: "%.2f"', 123.456789),
      Format('            scientific notation: "%e"', 123.456789),
      Format('scientific notation, 2 decimals: "%.2e"', 123.456789),
      Format(' scientific notation, uppercase: "%E"', 123.456789),
      Format('                             %%g: "%g"', 123.456789),
      Format('                 %%g, 2 decimals: "%.2g"', 123.456789),
      Format('                             %%G: "%g"', 123.456789),
      Format('                 %%G, 2 decimals: "%.2g"', 123.456789),

      Format('%nStrings:'),
      Repeat('-=', 30),
      Format('   normal: "%s"', 'Fauna'),
      Format('uppercase: "%S"', 'Fauna'),
      Format('     null: "%s"', null),
      Format('       %%%%: "%%"'),
      Format('linefeed: %n'),

      Format('%nBooleans:'),
      Repeat('=-', 30),
      Format('            true: "%b"', true),
      Format(' true, uppercase: "%B"', 1),
      Format('           false: "%b"', false),
      Format('false, uppercase: "%B"', 0),

      Format('%nTimes and Dates:'),
      Repeat('-=', 30),
      Format('                    ISO-8601: %t', Var('ts')),
      Format('         ISO-8601, uppercase: %T', Var('ts')),
      Format(''),
      Format('             Full month name: %tB', Var('ts')),
      Format('  Full month name, uppercase: %TB', Var('ts')),
      Format('            Short month name: %tb', Var('ts')),
      Format(' Short month name, uppercase: %Tb', Var('ts')),
      Format('                          %%h: %th', Var('ts')),
      Format('               %%h, uppercase: %Tb', Var('ts')),
      Format('                Full weekday: %tA', Var('ts')),
      Format('     Full weekday, uppercase: %TA', Var('ts')),
      Format('               Short weekday: %ta', Var('ts')),
      Format('    Short weekday, uppercase: %Ta', Var('ts')),
      Format('                     Century: %tC', Var('ts')),
      Format('                        Year: %tY', Var('ts')),
      Format('                  Short year: %ty', Var('ts')),
      Format('             Day of the year: %tj', Var('ts')),
      Format('                       Month: %tm', Var('ts')),
      Format('            Day of the month: %td', Var('ts')),
      Format(''),

      Format('      Hour, leading 0\'s (24): %tH', Var('ts')),
      Format('      Hour, leading 0\'s (12): %tI', Var('ts')),
      Format('                   Hour (24): %tk', Var('ts')),
      Format('                   Hour (12): %tl', Var('ts')),
      Format('                      Minute: %tM', Var('ts')),
      Format('                      Second: %tS', Var('ts')),
      Format('                 Millisecond: %tL', Var('ts')),
      Format('                  Nanosecond: %tN', Var('ts')),
      Format('           Morning/afternoon: %tp', Var('ts')),
      Format('Morning/afternoon, uppercase: %Tp', Var('ts')),
      Format('         Seconds since epoch: %ts', Var('ts')),
      Format('    Milliseconds since epoch: %tQ', Var('ts')),
      Format(''),

      Format('                          %%R: %tR', Var('ts')),
      Format('                          %%T: %tT', Var('ts')),
      Format('                          %%r: %tr', Var('ts')),
      Format('                          %%D: %tD', Var('ts')),
      Format('                          %%F: %tF', Var('ts')),
      Format('                          %%c: %tc', Var('ts')),
      Format(''),
    ],
    '\n'
  )
)
'\n' +
  'Decimals:\n' +
  '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n' +
  '                   normal: "123"\n' +
  '                with sign: "+123"\n' +
  '               with width: "    123"\n' +
  '   with width, align left: "123    "\n' +
  '           as hexadecimal: "7b"\n' +
  'as hexadecimal, uppercase: "7B"\n' +
  '                 as octal: "173"\n' +
  '\n' +
  'Floats:\n' +
  '=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n' +
  '                         normal: "123.456789"\n' +
  '                     2 decimals: "123.46"\n' +
  '            scientific notation: "1.234568e+02"\n' +
  'scientific notation, 2 decimals: "1.23e+02"\n' +
  ' scientific notation, uppercase: "1.234568E+02"\n' +
  '                             %g: "123.457"\n' +
  '                 %g, 2 decimals: "1.2e+02"\n' +
  '                             %G: "123.457"\n' +
  '                 %G, 2 decimals: "1.2e+02"\n' +
  '\n' +
  'Strings:\n' +
  '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n' +
  '   normal: "Fauna"\n' +
  'uppercase: "FAUNA"\n' +
  '     null: "null"\n' +
  '       %%: "%"\n' +
  'linefeed: \n' +
  '\n' +
  '\n' +
  'Booleans:\n' +
  '=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n' +
  '            true: "true"\n' +
  ' true, uppercase: "TRUE"\n' +
  '           false: "false"\n' +
  'false, uppercase: "TRUE"\n' +
  '\n' +
  'Times and Dates:\n' +
  '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n' +
  '                    ISO-8601: 2019-08-16T18:51:33.987654321Z\n' +
  '         ISO-8601, uppercase: 2019-08-16T18:51:33.987654321Z\n' +
  '\n' +
  '             Full month name: August\n' +
  '  Full month name, uppercase: AUGUST\n' +
  '            Short month name: Aug\n' +
  ' Short month name, uppercase: AUG\n' +
  '                          %h: Aug\n' +
  '               %h, uppercase: AUG\n' +
  '                Full weekday: Friday\n' +
  '     Full weekday, uppercase: FRIDAY\n' +
  '               Short weekday: Fri\n' +
  '    Short weekday, uppercase: FRI\n' +
  '                     Century: 20\n' +
  '                        Year: 2019\n' +
  '                  Short year: 19\n' +
  '             Day of the year: 228\n' +
  '                       Month: 08\n' +
  '            Day of the month: 16\n' +
  '\n' +
  "      Hour, leading 0's (24): 18\n" +
  "      Hour, leading 0's (12): 06\n" +
  '                   Hour (24): 18\n' +
  '                   Hour (12): 6\n' +
  '                      Minute: 51\n' +
  '                      Second: 33\n' +
  '                 Millisecond: 987\n' +
  '                  Nanosecond: 987654321\n' +
  '           Morning/afternoon: pm\n' +
  'Morning/afternoon, uppercase: PM\n' +
  '         Seconds since epoch: 1565981493\n' +
  '    Milliseconds since epoch: 1565981493987\n' +
  '\n' +
  '                          %R: 18:51\n' +
  '                          %T: 18:51:33\n' +
  '                          %r: 06:51:33 PM\n' +
  '                          %D: 08/16/19\n' +
  '                          %F: 2019-08-16\n' +
  '                          %c: Fri Aug 16 18:51:33 Z 2019\n'
Query metrics:
  •    bytesIn: 4,541

  •   bytesOut: 2,683

  • computeOps:     2

  •    readOps:     0

  •   writeOps:     0

  •  readBytes:     0

  • writeBytes:     0

  •  queryTime:  31ms

  •    retries:     0

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!