# Type Conversion

> Source: https://docs.recombee.com/reql/functions/type-conversion

> For the complete documentation index, see [llms.txt](/llms.txt).

# Type Conversion

| Name                              | Description                        | Example                                                    |
| --------------------------------- | ---------------------------------- | ---------------------------------------------------------- |
| [boolean](#reql-func-boolean)     | Converts the argument to boolean   | boolean("") == False                                       |
| [number](#reql-func-number)       | Converts the argument to number    | number("456") == 456                                       |
| [string](#reql-func-string)       | Converts the argument to string    | string(123) == "123"                                       |
| [timestamp](#reql-func-timestamp) | Converts the argument to timestamp | timestamp("2015-06-25T11:08:44Z") == timestamp(1435230524) |

## Boolean Conversion Function

Boolean conversion function is used for getting the truth value of any expression.

### Definition

```
boolean(value_to_be_converted)
```

| Argument                 | Type     | Meaning                              |
| ------------------------ | -------- | ------------------------------------ |
| value\_to\_be\_converted | any type | Value to be converted into a boolean |

### Examples

All the following expressions result in `true`:

```
boolean("Recombee") == true

boolean("") == False

boolean(42) == true

boolean(0) == False

boolean({""}) == true

boolean({}) == False
```

## Number Conversion Function

Number conversion function is used for converting strings, booleans and timestamps into numbers.

### Definition

```
number(value_to_be_converted)
```

| Argument                 | Type                            | Meaning                             |
| ------------------------ | ------------------------------- | ----------------------------------- |
| value\_to\_be\_converted | string boolean timestamp number | Value to be converted into a number |

### Examples

All the following expressions result in `true`:

```
number("456") == 456

number("1E4") == 10000

number(true) == 1

// String "Recombee" cannot be converted into a number
number("Recombee") == null
```

## String Conversion Function

String conversion function is used for converting numbers, booleans, sets and timestamps into their textual representations.

### Definition

```
string(value_to_be_converted [, date_time_format (only if value_to_be_converted is a timestamp)])
```

| Argument                 | Type                                | Meaning                                                                                                                                                                                                                                                                                                                                        |
| ------------------------ | ----------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| value\_to\_be\_converted | string boolean timestamp set number | Value to be converted into a string                                                                                                                                                                                                                                                                                                            |
| date\_time\_format       | string                              | _(Optional and only if value\_to\_be\_converted is a timestamp)_ String specifying the format of textual representation of the timestamp after conversion. [See supported date and time format specifiers](/time_specifiers). If date\_time\_format is not specified, [ISO 8601](https://en.wikipedia.org/?title=ISO_8601) format is used. |

### Examples

All the following expressions result in `true`:

```
string(123) == "123"

string(true) == "true"

// Suppose that 'time' is a timestamp with value 1435230524. No format string is specified, so ISO 8601 is used.
string('time') == "2015-06-25T11:08:44Z"

// Suppose that 'time' is a timestamp with value 1435230524.
string('time', "%d.%m.%Y %H:%M:%S") == "25.06.2015 11:08:44"
```

## Timestamp Conversion Function

Timestamp conversion function is used for converting numbers and strings into timestamps.

### Definition

```
timestamp(value_to_be_converted [, date_time_format (only if value_to_be_converted is a string) ] )
```

| Argument                 | Type                    | Meaning                                                                                                                                                                                                                                                                                                     |
| ------------------------ | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| value\_to\_be\_converted | string number timestamp | Value to be converted into a string                                                                                                                                                                                                                                                                         |
| date\_time\_format       | string                  | _(Optional and only if value\_to\_be\_converted is a string)_ String specifying the format of value\_to\_be\_converted. [See supported date and time format specifiers](/time_specifiers). If date\_time\_format is not specified, [ISO 8601](https://en.wikipedia.org/?title=ISO_8601) format is used. |

### Examples

All the following expressions result in `true`:

```
// No format string is specified, so ISO 8601 is used.
timestamp("2015-06-25T11:08:44Z") == timestamp(1435230524)

timestamp("25.06.2015 11:08:44", "%d.%m.%Y %H:%M:%S") == timestamp(1435230524)
```