Skip to content
Advertisement

How to create Date and Hour columns from Seconds column using SQL

I have a column called Time with float values giving time in seconds after the first event occurred. I was wondering how to create columns called Date and Hour using this column in SQL.

My dataset is big, I can not use Pandas.

Setup

Data

pyspark dataframe

Using pandas (but I need pyspark)

Question

How to get the new column Date and Hour using SQL and Pyspark like I just did in pandas. I have big data that I can not use pandas and I have to use pyspark for that. Thanks.

Advertisement

Answer

You can use functions: timestamp, unix_timestamp and hour:

Note: use timestamp function to keep the microsecond

Use SQL syntax:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement