0
0
Apache Sparkdata~5 mins

Date and timestamp functions in Apache Spark - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the current_date() function return in Apache Spark?
The current_date() function returns the current date as a DateType value without the time part.
Click to reveal answer
beginner
How do you extract the year from a timestamp column in Spark?
Use the year() function to get the year part from a timestamp or date column.
Click to reveal answer
intermediate
What is the difference between unix_timestamp() and to_timestamp() functions?
unix_timestamp() returns the number of seconds since 1970-01-01 00:00:00 UTC as a long integer, while to_timestamp() converts a string to a timestamp type.
Click to reveal answer
beginner
How can you add 5 days to a date column in Spark?
Use the date_add(dateColumn, 5) function to add 5 days to the date in dateColumn.
Click to reveal answer
beginner
What does the datediff(end, start) function compute?
It calculates the number of days between two dates: end minus start.
Click to reveal answer
Which function returns the current timestamp in Spark?
Acurrent_date()
Bcurrent_timestamp()
Cunix_timestamp()
Dto_date()
How do you convert a string like '2024-06-01 12:30:00' to a timestamp in Spark?
Adate_add('2024-06-01 12:30:00', 1)
Bunix_timestamp('2024-06-01 12:30:00')
Cto_date('2024-06-01 12:30:00')
Dto_timestamp('2024-06-01 12:30:00')
What does date_sub(dateColumn, 3) do?
ASubtracts 3 days from dateColumn
BReturns the day of the month
CAdds 3 days to dateColumn
DConverts dateColumn to string
Which function gives the number of seconds since 1970-01-01 00:00:00 UTC?
Ayear()
Bcurrent_date()
Cunix_timestamp()
Dto_timestamp()
If you want to find the difference in days between two dates, which function do you use?
Adatediff()
Bdate_add()
Cdate_sub()
Dyear()
Explain how to convert a string to a timestamp and then extract the year in Apache Spark.
Think about the functions to convert and then extract parts of a date.
You got /4 concepts.
    Describe how to calculate the number of days between two date columns in Spark.
    Focus on the function that measures days difference.
    You got /3 concepts.