unix_timestamp
function
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 ifexpr
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 for valid date and time format patterns.
If fmt
or expr
are invalid the function raises an error.
Note
In Databricks Runtime, if spark.sql.ansi.enabled is false
, the function returns NULL
instead of an error for malformed timestamps.
Examples
> SELECT unix_timestamp();
1476884637
> SELECT unix_timestamp('2016-04-08', 'yyyy-MM-dd');
1460041200
Related functions
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for