---
title: "Mathematics and Date/Time"
description: "iXML Math and Date namespaces for arithmetic, trigonometry, rounding, random numbers, number formatting, timestamps, and date formatting."
canonical_url: "https://www.zeyos.com/ixml/ixml-guide/standard-library/math-datetime"
markdown_url: "https://www.zeyos.com/ai/guide/ixml/ixml-guide/standard-library/math-datetime.md"
section: "ixml-guide"
authority: "guide"
language: "en"
source_repository: "zeyos/guide"
source_path: "docs/ixml/10-standard-library/math-datetime.md"
source_revision: "cce886a8da98cd124ee3644711085bbdcf1a87ce"
---

# Mathematics and Date/Time

The **Math** namespace provides arithmetic, trigonometry, rounding, random numbers, base conversion, and number formatting. The **Date** namespace provides Unix timestamp operations: retrieving, creating, decomposing, parsing, and formatting dates.

:::note Timestamp model
All date/time operations use **Unix timestamps** — seconds since January 1, 1970 00:00:00 UTC. There is no separate Date type; dates are always numeric timestamps.
:::

---

## Basic arithmetic

### `math:abs` — Absolute value

Returns the non-negative magnitude of a number.

```xml
<output><math:abs>-13.74</math:abs></output>
<!-- 13.74 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-abs)

---

### `math:sign` — Extract sign

Returns `1` (positive), `0` (zero), or `-1` (negative).

```xml
<output><math:sign>-13.74</math:sign></output>
<!-- -1 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-sign)

---

### `math:inc` — Increment variable

Increments a variable in place by a given amount (default 1). This is the idiomatic way to build counters in iXML.

```xml
<set var="number">1</set>
<math:inc var="number" />
<output>$number</output>
<!-- 2 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-inc)

---

### `math:dec` — Decrement variable

Decrements a variable in place by a given amount (default 1).

```xml
<set var="number">2</set>
<math:dec var="number" />
<output>$number</output>
<!-- 1 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-dec)

---

### `math:mod` — Floating-point modulo

Returns the remainder of dividing `x` by `y`. Supports fractional values.

```xml
<output><math:mod x="5.72" y="1.38" /></output>
<!-- 0.2 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-mod)

---

## Exponential and logarithmic functions

### `math:exp` — Natural exponential

Raises Euler's number (*e*) to the given power.

```xml
<output><math:exp>10</math:exp></output>
<!-- 22026.465794807 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-exp)

---

### `math:ln` — Natural logarithm

Computes the base-*e* logarithm. Input must be positive.

```xml
<output><math:ln>22026.465794807</math:ln></output>
<!-- 10 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-ln)

---

### `math:log` — Logarithm with base

Computes the logarithm with a specified base (default 10).

```xml
<output><math:log base="2">1024</math:log></output>
<!-- 10 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-log)

---

### `math:pow` — Raise to power

Raises a value to the given exponent (default 2).

```xml
<output><math:pow exponent="10">2</math:pow></output>
<!-- 1024 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-pow)

---

### `math:sqrt` — Square root

Returns the square root of a non-negative value.

```xml
<output><math:sqrt>25</math:sqrt></output>
<!-- 5 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-sqrt)

---

### `math:hypot` — Hypotenuse

Computes sqrt(x^2 + y^2) with better numerical precision than doing it manually.

```xml
<output><math:hypot x="3" y="5" /></output>
<!-- 5.8309518948453 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-hypot)

---

## Constants

### `math:pi` — Circle constant

Returns the mathematical constant pi with full floating-point precision.

```xml
<output><math:pi /></output>
<!-- 3.1415926535898 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-pi)

---

## Trigonometric functions

All trigonometric functions operate in **radians**. Use `math:convert` to convert between degrees and radians.

### Standard trigonometric functions

| Command | Description |
|---|---|
| `math:sin` | Sine of an angle |
| `math:cos` | Cosine of an angle |
| `math:tan` | Tangent of an angle |

```xml
<output><math:sin>1</math:sin></output>
<!-- 0.8414709848079 -->
```

[`math:sin` reference →](https://www.zeyos.com/ixml/ref/math-sin) | [`math:cos` reference →](https://www.zeyos.com/ixml/ref/math-cos) | [`math:tan` reference →](https://www.zeyos.com/ixml/ref/math-tan)

### Inverse (arc) functions

| Command | Description |
|---|---|
| `math:asin` | Arc sine — returns radians (input in [-1, 1]) |
| `math:acos` | Arc cosine — returns radians (input in [-1, 1]) |
| `math:atan` | Arc tangent — returns radians in (-pi/2, pi/2) |
| `math:atan2` | Two-argument arc tangent — quadrant-aware, returns radians in (-pi, pi] |

```xml
<output><math:atan2 x="3" y="5" /></output>
<!-- 1.0303768265243 -->
```

[`math:asin` →](https://www.zeyos.com/ixml/ref/math-asin) | [`math:acos` →](https://www.zeyos.com/ixml/ref/math-acos) | [`math:atan` →](https://www.zeyos.com/ixml/ref/math-atan) | [`math:atan2` →](https://www.zeyos.com/ixml/ref/math-atan2)

### Hyperbolic functions

| Command | Description |
|---|---|
| `math:sinh` | Hyperbolic sine |
| `math:cosh` | Hyperbolic cosine |
| `math:tanh` | Hyperbolic tangent |
| `math:asinh` | Inverse hyperbolic sine |
| `math:acosh` | Inverse hyperbolic cosine (input >= 1) |
| `math:atanh` | Inverse hyperbolic tangent (input in (-1, 1)) |

```xml
<output><math:sinh>1</math:sinh></output>
<!-- 1.1752011936438 -->
```

[`math:sinh` →](https://www.zeyos.com/ixml/ref/math-sinh) | [`math:cosh` →](https://www.zeyos.com/ixml/ref/math-cosh) | [`math:tanh` →](https://www.zeyos.com/ixml/ref/math-tanh) | [`math:asinh` →](https://www.zeyos.com/ixml/ref/math-asinh) | [`math:acosh` →](https://www.zeyos.com/ixml/ref/math-acosh) | [`math:atanh` →](https://www.zeyos.com/ixml/ref/math-atanh)

---

## Rounding

### `math:round` — Round to precision

Rounds a value to a specified number of decimal places. Supports 10 rounding strategies via the `type` attribute. Default mode is `half-infinity` (ties round away from zero).

**Nearest-value modes:** `half-infinity` (default), `half-zero`, `half-up`, `half-down`, `half-even` (banker's rounding), `half-odd`.

**Directed modes:** `infinity` (away from zero), `zero` (truncate), `up` (ceiling), `down` (floor).

```xml
<output><math:round precision="2">17.213482971852</math:round></output>
<!-- 17.21 -->
```

For financial calculations, use `half-even` to minimize cumulative rounding error:

```xml
<output><math:round precision="2" type="half-even">2.555</math:round></output>
<!-- 2.56 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-round)

---

### `math:ceil` — Ceiling

Rounds a value **up** to the next highest integer.

```xml
<output><math:ceil>17.213482971852</math:ceil></output>
<!-- 18 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-ceil)

---

### `math:floor` — Floor

Rounds a value **down** to the next lowest integer.

```xml
<output><math:floor>17.213482971852</math:floor></output>
<!-- 17 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-floor)

---

## Random numbers

### `math:rand` — Generate random number

Generates a random integer. Optionally specify `min` and `max` for a range (inclusive).

```xml
<set var="diceRoll"><math:rand min="1" max="6" /></set>
<output>You rolled: $diceRoll</output>
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-rand)

---

## Number conversion

### `math:convert` — Convert number representation

Converts between number bases and angular units. Supported representations: `bin`, `oct`, `dec` (default), `hex`, `deg`, `rad`.

```xml
<!-- Hex to binary -->
<output><math:convert from="hex" to="bin">7cd5a72c</math:convert></output>
<!-- 1111100110101011010011100101100 -->
```

Particularly useful for converting degrees to radians before trigonometric operations:

```xml
<output>
    sin(45deg) = <math:sin><math:convert from="deg" to="rad">45</math:convert></math:sin>
</output>
<!-- sin(45deg) = 0.70710678118655 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-convert)

---

## Number formatting

### `math:format` — Format number for display

Produces a display string with fixed decimal places, configurable decimal point (`decpoint`), and thousands separator (`separator`). Returns a **string**, not a number -- do not use the result in further arithmetic.

```xml
<output><math:format countdec="2">1792702.213482971852</math:format></output>
<!-- 1,792,702.21 -->
```

German locale example:

```xml
<output><math:format countdec="2" decpoint="," separator=".">1792702.213482971852</math:format></output>
<!-- 1.792.702,21 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/math-format)

---

## Date and time

### `date:now` — Current timestamp

Returns the current Unix timestamp. Use `micro="true"` for microsecond precision (returns a float).

```xml
<date:now var="timestamp" />
<output>Current timestamp: $timestamp</output>
```

[Full reference →](https://www.zeyos.com/ixml/ref/date-now)

---

### `date:info` — Decompose timestamp

Breaks a timestamp into components: `day`, `month`, `year`, `hour`, `minute`, `second`, `wday` (0=Sunday..6=Saturday), `yday`. If no timestamp given, uses the current time.

```xml
<date:info var="now" />
<output>Today is $now.year-$now.month-$now.day</output>
```

Supports the `timezone` attribute for time zone-aware decomposition:

```xml
<date:info var="berlin" timezone="Europe/Berlin">946684800</date:info>
<output>In Berlin: $berlin.year-$berlin.month-$berlin.day $berlin.hour:$berlin.minute</output>
<!-- In Berlin: 2000-1-1 1:0 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/date-info)

---

### `date:create` — Create timestamp from components

Constructs a Unix timestamp from `day`, `month`, `year` (required) and optionally `hour`, `minute`, `second`, `timezone`. Returns `NULL` for invalid dates.

```xml
<output><date:create day="1" month="1" year="2000" /></output>
<!-- 946684800 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/date-create)

---

### `date:parse` — Parse date string

Converts a date string into a Unix timestamp. Accepts ISO 8601, common formats, and relative expressions. Returns `NULL` if unparseable. Use `timezone` to set the assumed time zone for strings without explicit zone info.

:::warning
Always verify parsed results. Ambiguous formats (e.g., `01/02/2025` -- is that Jan 2 or Feb 1?) may not parse as expected. Prefer ISO 8601 (`YYYY-MM-DD`) when possible.
:::

```xml
<output><date:parse>2000-01-01</date:parse></output>
<!-- 946684800 -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/date-parse)

---

### `date:format` — Format timestamp

Converts a timestamp to a string using **PHP-compatible format characters**. If no timestamp given, uses the current time. Default format is `c` (ISO 8601).

**Common format characters:**

| Char | Output | Example |
|---|---|---|
| `Y` | 4-digit year | `2025` |
| `m` | Month (zero-padded) | `03` |
| `d` | Day (zero-padded) | `15` |
| `H` | Hour 24h (zero-padded) | `14` |
| `i` | Minute (zero-padded) | `30` |
| `s` | Second (zero-padded) | `00` |
| `c` | ISO 8601 full | `2025-03-15T14:30:00+01:00` |
| `D` | Day name (3-letter) | `Sat` |
| `F` | Month name (full) | `March` |

```xml
<output><date:format format="Y-m-d">946684800</date:format></output>
<!-- 2000-01-01 -->
```

European format with time zone:

```xml
<output><date:format format="d.m.Y H:i:s" timezone="Europe/Berlin">946684800</date:format></output>
<!-- 01.01.2000 01:00:00 -->
```

:::warning
Literal characters matching format codes must be backslash-escaped. For example, `\a\t` produces the text "at", not the `a` (am/pm) and `t` (days in month) format codes.
:::

[Full reference →](https://www.zeyos.com/ixml/ref/date-format)
