pyspark datetime add hours 1

pyspark datetime add hours

# PYSPARK DATAFRAME API

from pyspark.sql.functions import unix_timestamp

df.select((unix_timestamp(df.timestamp_col) + 3600).cast('timestamp'))
# 1 hour = 60 seconds x 60 minutes = 3600 seconds

Here is what the above code is Doing:
1. unix_timestamp() converts the timestamp_col to seconds since the epoch
2. + 3600 adds 1 hour to the timestamp
3. cast(‘timestamp’) converts the result back to a timestamp

Similar Posts