1
有與事件和特定的時間戳的表之間的差異。我很難計算使用Pyspark 2.0 API傳遞的天數。我設法做同樣的事情,當時間戳另一種格式(YYYY-MM-DD)Pyspark:兩個Date(演員TimestampType,則DateDiff)
+-------------------+------------------------+----------+--------------+
| first_booking_date|first_booking_date_clean| today |customer_since|
+-------------------+------------------------+----------+--------------+
|02-06-2011 20:52:04| 02-06-2011|02-06-2011| null|
|03-06-2004 18:15:10| 03-06-2004|02-06-2011| null|
我嘗試以下(無工作): - 提取日期字符串操作和使用DATEDIFF - 轉換成時間戳,然後提取dd:MM:yy( - > result null) - 我更喜歡使用pyspark命令通過任何其他轉換使用sql
幫助非常感謝,最好,非常感謝!
編輯:這裏是沒有工作的例子:
import datetime
today = datetime.date(2011,2,1)
today = "02-06-2011"
first_bookings = first_bookings.withColumn("today",F.lit(today))
first_bookings = first_bookings.withColumn("first_booking_date_clean",F.substring(first_bookings.first_booking_date, 0, 10))
first_bookings = first_bookings.withColumn("customer_since",F.datediff(first_bookings.today,first_bookings.first_booking_date_clean))
如果需要,歡迎加入更多信息! –
https://stackoverflow.com/a/36985244/4219202看看這個答案類似的問題。在你的情況timefmt的將是「DD-MM-YYYY」爲列first_booking_date_clean今天 – Zephro
[減去字符串格式兩個日期時間列計算時間]的可能的複製(https://stackoverflow.com/questions/30283415/calculating -duration逐減法,二,日期時間,列式串格式) – sdikby