> ## Documentation Index
> Fetch the complete documentation index at: https://docs.narrative.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Date & Time Functions

> Temporal operations: DATE_TRUNC, DATE_ADD, FORMAT_TIMESTAMP, and more

## Date and time functions

### CURRENT\_DATE

Returns the current date.

```sql theme={null}
SELECT CURRENT_DATE -- '2024-01-15'
SELECT user_id, email, event_date FROM company_data."123" WHERE event_date = CURRENT_DATE
```

### CURRENT\_TIMESTAMP

Returns the current timestamp.

```sql theme={null}
SELECT CURRENT_TIMESTAMP -- '2024-01-15 14:30:00'
```

### DATE\_ADD

Adds days to a date.

```sql theme={null}
SELECT DATE_ADD('2024-01-01', 7) -- '2024-01-08'
SELECT DATE_ADD(start_date, 30) AS end_date FROM company_data."123"
```

### DATE\_SUB

Subtracts days from a date.

```sql theme={null}
SELECT DATE_SUB(CURRENT_DATE, 7) -- 7 days ago
```

### DATEDIFF

Returns the number of days between two dates.

```sql theme={null}
SELECT DATEDIFF('2024-01-10', '2024-01-01') -- 9
SELECT DATEDIFF(end_date, start_date) AS duration FROM company_data."123"
```

### DATE\_TRUNC

Truncates a timestamp to a specified precision.

```sql theme={null}
SELECT DATE_TRUNC('day', '2024-01-15 14:30:00')   -- '2024-01-15 00:00:00'
SELECT DATE_TRUNC('month', '2024-01-15 14:30:00') -- '2024-01-01 00:00:00'
SELECT DATE_TRUNC('year', '2024-01-15 14:30:00')  -- '2024-01-01 00:00:00'
```

**Supported units:** `year`, `month`, `day`, `hour`, `minute`, `second`

### EXTRACT

Extracts a component from a date or timestamp.

```sql theme={null}
SELECT EXTRACT(YEAR FROM '2024-01-15')  -- 2024
SELECT EXTRACT(MONTH FROM '2024-01-15') -- 1
SELECT EXTRACT(DAY FROM '2024-01-15')   -- 15
SELECT EXTRACT(HOUR FROM '2024-01-15 14:30:00') -- 14
```

**Supported parts:** `YEAR`, `MONTH`, `DAY`, `HOUR`, `MINUTE`, `SECOND`, `DAYOFWEEK`, `DAYOFYEAR`

### TO\_DATE

Converts a string to a date.

```sql theme={null}
SELECT TO_DATE('2024-01-15') -- DATE '2024-01-15'
SELECT TO_DATE(date_string) FROM company_data."123"
```

### TO\_TIMESTAMP

Converts a string to a timestamp.

```sql theme={null}
SELECT TO_TIMESTAMP('2024-01-15 10:30:00')
```

### FROM\_UNIXTIME

Converts Unix epoch seconds to timestamp.

```sql theme={null}
SELECT FROM_UNIXTIME(1705312200) -- '2024-01-15 10:30:00'
SELECT FROM_UNIXTIME(epoch_seconds) AS event_time FROM company_data."123"
```

### UNIX\_TIMESTAMP

Converts a timestamp to Unix epoch seconds.

```sql theme={null}
SELECT UNIX_TIMESTAMP('2024-01-15 10:30:00') -- 1705312200
SELECT UNIX_TIMESTAMP(event_timestamp) AS epoch FROM company_data."123"
```

### FORMAT\_TIMESTAMP

Formats a timestamp column using a specified pattern string. Returns the formatted timestamp as a string.

```sql theme={null}
SELECT
  FORMAT_TIMESTAMP('YYYY-MM-DD', timestamp_col) AS date_only,
  FORMAT_TIMESTAMP('HH24:MI:SS', timestamp_col) AS time_only,
  FORMAT_TIMESTAMP('YYYY-MM-DDTHH24:MI:SS', timestamp_col) AS iso_no_tz,
  FORMAT_TIMESTAMP('YYYY-MM-DDTHH24:MI:SS TZH', timestamp_col) AS iso_with_tz,
  FORMAT_TIMESTAMP('YYYY-MM-DDTHH24:MI:SS TZH:TZM', timestamp_col) AS iso_with_full_tz
FROM company_data."123"
```

**Common patterns:**

* `YYYY-MM-DD` — Date only (2024-01-15)
* `HH24:MI:SS` — 24-hour time (14:30:00)
* `YYYY-MM-DDTHH24:MI:SS` — ISO 8601 without timezone
* `YYYY-MM-DDTHH24:MI:SS TZH:TZM` — ISO 8601 with full timezone offset

See [Snowflake date/time format elements](https://docs.snowflake.com/en/sql-reference/date-time-input-output#about-the-elements-used-in-input-and-output-formats) for all supported pattern elements.

***

## Related content

<CardGroup cols={2}>
  <Card title="Numeric Functions" icon="hashtag" href="/nql/functions/numeric-functions">
    Math and rounding
  </Card>

  <Card title="String Functions" icon="font" href="/nql/functions/string-functions">
    Text manipulation
  </Card>

  <Card title="All Functions" icon="function" href="/nql/functions/index">
    Browse all function categories
  </Card>

  <Card title="Data Types" icon="shapes" href="/nql/data-types">
    DATE and TIMESTAMP type reference
  </Card>
</CardGroup>
