Spark SQL - UNIX timestamp functions

visibility 1,340 access_time 2 years ago languageEnglish

Current UNIX timestamp

Function unix_timestamp() returns the UNIX timestamp of current time. You can also specify a input timestamp value. 


spark-sql> select unix_timestamp();
unix_timestamp(current_timestamp(), yyyy-MM-dd HH:mm:ss)

spark-sql> select unix_timestamp(current_timestamp, 'yyyy-MM-dd');
unix_timestamp(current_timestamp(), yyyy-MM-dd)

UNIX timestamp string to date

Function from_unixtime(unix_time, format) can be used to convert UNIX time to Spark SQL date data type. 


spark-sql> select from_unixtime(1610174365, 'yyyy-MM-dd');
from_unixtime(CAST(1610174365 AS BIGINT), yyyy-MM-dd)

UNIX timestamp string to timestamp

Function from_unixtime(unix_time, format) can also be used to convert UNIX time to Spark SQL timestamp data type. 


spark-sql> select from_unixtime(1610174099, 'yyyy-MM-dd HH:mm:ss');
from_unixtime(CAST(1610174099 AS BIGINT), yyyy-MM-dd HH:mm:ss)
2021-01-09 17:34:59
copyright This page is subject to Site terms.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

timeline Stats
Page index 2.70
More from Kontext
Spark SQL - ROW_NUMBER Window Functions
visibility 9,534
thumb_up 0
access_time 2 years ago
Spark SQL - Average (AVG) Calculation
visibility 226
thumb_up 0
access_time 8 months ago