Working With Timestamps in Spark

Working with timestamps while processing data can be a headache sometimes. Luckily Spark has some in-built functions to make our life easier when working with timestamps. Let us go over these functions.

current_timestamp – Getting Current Timestamp

We can get current timestamp using current_timestamp function.

date_trunc – Truncated Date From Timestamp

We can get truncated date from timestamp using code below.

timestamp_trunc

Converting Timestamp to Unix Timestamp

Spark has provided function to convert timestamp to Unix Timestamp.

Get Timestamp from Unix Timestamp

Get Timestamp from Date

We can also get from timestamp using to_timestamp function

I hope you found this helpful. See you in in next blog.

Working With Timestamps in Spark

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *