unix_timestamp
function
Returns the UNIX timestamp of current or specified time.
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
If spark.sql.ansi.enabled is false
the function returns NULL
instead of an error for malformed timestamps.