Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Extract the seconds of a given date as integer.
For the corresponding Databricks SQL function, see second function.
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.second(col=<col>)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column or str |
target date/time/timestamp column to work on. |
Returns
pyspark.sql.Column: seconds part of the timestamp as integer.
Examples
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('2015-04-08 13:08:15',), ('2024-10-31 10:09:16',)], ['ts'])
df.select("*", dbf.typeof('ts'), dbf.second('ts')).show()
import datetime
df = spark.createDataFrame([
(datetime.datetime(2015, 4, 8, 13, 8, 15),),
(datetime.datetime(2024, 10, 31, 10, 9, 16),)], ['ts'])
df.select("*", dbf.typeof('ts'), dbf.second('ts')).show()
import datetime
df = spark.createDataFrame([
("13:08:15",),
("10:09:16",)], ['t']).withColumn("t", dbf.col("t").cast("time"))
df.select("*", dbf.typeof('t'), dbf.second('t')).show()