I am doing the following to get workdays and work hours excluding weekends.
case = case.withColumn('days_h', F.expr('sequence(CreatedDate, ClosedDate, interval 1 hour)'))\
.withColumn('weekdays_h', F.expr('filter(transform(days_h, day->(day, extract(dow_iso from day))), day -> day.col2 <=5).day'))\
case = case.withColumn("from_work_day", F.col('weekdays_h')[0])
case = case.withColumn("to_work_day", F.element_at(F.col('weekdays_h'), -1))
timeDiff = (F.col('to_work_day').cast('long') - F.col('from_work_day').cast('long'))
case = case.withColumn("Duration", timeDiff).withColumn('Diff_in_Hours', F.round(F.col('Duration')/3600))
In the below screenshot, I must get 482 hrs, but instead I get 672 hrs which is including weekend dates.
Is there a way to calculate hours of the dates in the array which is exclusive of weekends?
