SQL: DATEDIFF(mi, ClockInUTC_End,ClockInUTC_Snd( TimeinMinutes
我想在PySpark SQL中使用它的替代方案。 火花.sql("(
您可以使用unix_timestamp函数来执行此操作,该函数基本上转换为UTC格式的UNIX纪元值。请参考下面的代码。
spark.sql("""
SELECT "2019-12-18 06:30:00" AS ClockInUTC_End,
"2019-12-18 06:00:00" AS ClockInUTC_Snd,
CAST((unix_timestamp("2019-12-18 06:30:00", "yyyy-MM-dd HH:mm:ss")
- unix_timestamp("2019-12-18 06:00:00", "yyyy-MM-dd HH:mm:ss"))/60 AS INT) AS Diff_In_Minutes
""").show(20,False)
Output :
+-------------------+-------------------+---------------+
|ClockInUTC_End |ClockInUTC_Snd |Diff_In_Minutes|
+-------------------+-------------------+---------------+
|2019-12-18 06:30:00|2019-12-18 06:00:00|30 |
+-------------------+-------------------+---------------+