Muistiinpano
Tämän sivun käyttö edellyttää valtuutusta. Voit yrittää kirjautua sisään tai vaihtaa hakemistoa.
Tämän sivun käyttö edellyttää valtuutusta. Voit yrittää vaihtaa hakemistoa.
Applies to:
Databricks SQL
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 ifexpris 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 for valid date and time format patterns.
If fmt or expr are invalid, Azure Databricks raises CANNOT_PARSE_TIMESTAMP.
Note
In Databricks Runtime, if spark.sql.ansi.enabled is false, the function returns NULL instead of an error for malformed timestamps.
Common error conditions
Examples
> 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