coerce.to-string

coerce.to-string attempts to parse unknown data to a string. It is a flexible method, and will attempt to take any primitive data type and encode it as a string.

Function category: Coercion

Syntax

coerce.to-string(arg1, arg2)

Arguments

Description

arg1

Any date.

arg2

Optional. A format string.

Date Format String

For coercing Date objects to a string, an optional format string can be supplied. All letters 'A' to 'Z' and 'a' to 'z' are reserved as format letters. The following letters are defined:

Symbol

Meaning

Example

G

era

AD

u

year

2004

y

year of era

2004

D

day of year

189

M/L

month of year

7

d

day of month

10

Q

quarter of year

3

Y

week based year

2004

w

week of week based year

27

W

week of month

4

E/e/C

day of week

Tue

F

week of month

3

a

am/pm of day

PM

h

clock hour of am/pm (1-12)

12

K

hour of am/pm (0-11)

0

k

clock hour of am/pm (1-24)

12

H

hour of day (0-23)

0

m

minute of hour

30

s

second of minute

35

S

fraction of second

913

A

milli of day

3456

n

nano of second

987654321

N

nano of day

1234000000

V

time zone ID

Europe/Berlin

z

time zone name

CET

O

zone offset

GMT+2

X

zone offset; Z for zero

Z | +02

x

zone offset

+0000 | +02

Z

zone offset

+0000 | +0200

The text style / number of digits is determined based on the number of letters used in the format string.

To use a letter as a letter within a format string, quote it using single quotation marks (').

Examples

Example 1: Boolean to string

If we have a function that is given a Boolean as its argument, this function returns a string value.

# Boolean to string
coerce.to-string(true)
# Returns "true"

Example 2: Integer to string

If we have a function that is given an integer as an argument, this function returns a string.

# Integer to string
coerce.to-string(1.1)
# Returns "1.1"

Example 3: Specify a time output format for string

If we have a function that includes a time output, such as DATE, as an argument, this function returns a string based on the format specified.

# Date to string
coerce.to-string(DATE(1988, 8, 21), 'MMM-yy-dd')
# Returns AUG-88-21
coerce.to-string(NOW(), "YYYY-MM-dd'T'HH:mm:ssZ")
# Returns 2020-01-17T11:22:33+0200

Notes