---
title: unix_timestamp function
description: Learn the syntax of the unix\_timestamp function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/unix_timestamp
---

# `unix_timestamp` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Returns the UNIX timestamp of current or specified time.

## Syntax

```
unix_timestamp([expr [, fmt] ] )
```

## Arguments

* `expr`: An optional DATE, TIMESTAMP, or a STRING expression in a valid datetime format.
* `fmt`: An optional STRING expression specifying the format if `expr` is a STRING.

## Returns

A BIGINT.

If no argument is provided the default is the current timestamp.
`fmt` is ignored if `expr` is a DATE or TIMESTAMP.
If `expr` is a STRING `fmt` is used to translate the string to a TIMESTAMP before computing the unix timestamp.

The default `fmt` value is `'yyyy-MM-dd HH:mm:ss'`.

See [Datetime patterns](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-datetime-pattern.md) for valid date and time format patterns.

If `fmt` or `expr` are invalid, Databricks raises [CANNOT\_PARSE\_TIMESTAMP](https://docs.databricks.com/aws/en/error-messages/error-classes.md#cannot_parse_timestamp).

> [!NOTE]
>
> In Databricks Runtime, if [spark.sql.ansi.enabled](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-ansi-compliance.md) is `false`, the function returns `NULL` instead of an error for malformed timestamps.

## Common error conditions

* [CANNOT\_PARSE\_TIMESTAMP](https://docs.databricks.com/aws/en/error-messages/error-classes.md#cannot_parse_timestamp)

## Examples

```sql
> SELECT unix_timestamp();
 1476884637
> SELECT unix_timestamp('2016-04-08', 'yyyy-MM-dd');
 1460041200

> SELECT unix_timestamp('not-a-timestamp', 'yyyy-MM-dd');
  Error: CANNOT_PARSE_TIMESTAMP
```

## Related functions

* [`timestamp` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/timestamp.md)
