Pular para o conteúdo principal

diferença_de_tempo

Retorna a diferença entre dois horários, medida nas unidades especificadas.

Sintaxe​

Python
from pyspark.sql import functions as dbf

dbf.time_diff(unit=<unit>, start=<start>, end=<end>)

Parâmetros​

Parâmetro

Tipo

Descrição

unit

pyspark.sql.Column ou str

A unidade para truncar o tempo. As unidades suportadas são: "HORA", "MINUTO", "SEGUNDO", "MILISSEGUNDO" e "MICROSEGUNDO". A unidade não diferencia maiúsculas de minúsculas.

start

pyspark.sql.Column ou str

Horário de início.

end

pyspark.sql.Column ou str

Um tempo que termina.

Parâmetro

Tipo

Descrição

unit

pyspark.sql.Column ou str

A unidade para truncar o tempo. As unidades suportadas são: "HORA", "MINUTO", "SEGUNDO", "MILISSEGUNDO" e "MICROSEGUNDO". A unidade não diferencia maiúsculas de minúsculas.

start

pyspark.sql.Column ou str

Horário de início.

end

pyspark.sql.Column ou str

Um tempo que termina.

Devoluções​

pyspark.sql.ColumnA diferença entre dois horários, nas unidades especificadas.

Exemplos​

Python
from pyspark.sql import functions as dbf
df = spark.createDataFrame(
[("HOUR", "13:08:15", "21:30:28")], ['unit', 'start', 'end']).withColumn("start",
dbf.col("start").cast("time")).withColumn("end", dbf.col("end").cast("time"))
df.select('*', dbf.time_diff('unit', 'start', 'end')).show()